Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- - Replace with the name of your projectile model or part local projectileName = Blast - Wizard local tool = script.Parent.Parent - - Go

-- Replace with the name of your projectile model or part
local projectileName = "Blast-Wizard"
local tool = script.Parent.Parent -- Go up two levels to reach the Handle of the Staff-Wizard tool
-- Configurable parameters
local damageAmount =10-- Adjust the damage as needed
-- Preload the projectile model from ReplicatedStorage
local replicatedStorage = game:GetService("ReplicatedStorage")
local projectile = replicatedStorage:WaitForChild(projectileName)
local function shootProjectile()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local origin = humanoid.Parent:WaitForChild("HumanoidRootPart").Position
local direction =(mouse.Hit.p - origin).unit
local newProjectile = projectile:Clone()
newProjectile.Parent = game.Workspace
newProjectile.Position = origin
-- Attach BodyPosition to update the position of the projectile
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.Position = origin + direction *50-- Adjust the distance as needed
bodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyPosition.Parent = newProjectile
local hasDealtDamage = false -- Flag to ensure damage is applied only once
local function onTouched(hit)
if hasDealtDamage then
return
end
local hitHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if hitHumanoid and hit.Parent ~= humanoid.Parent then
-- Deal damage or perform other actions as needed
hitHumanoid:TakeDamage(damageAmount)
hasDealtDamage = true -- Set the flag to true to prevent further damage
newProjectile:Destroy()
elseif hit.Parent:IsA("Terrain") then
-- Handle terrain collision if needed
newProjectile:Destroy()
end
end
newProjectile.Touched:Connect(onTouched)
-- Remove the projectile after 3 seconds (adjust as needed)
wait(3)
newProjectile:Destroy()
end
tool.Activated:Connect(shootProjectile)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

2.5 Describe a social audit.

Answered: 1 week ago