Question: - - 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!