The code is in a local script inside a tool and under it is the handle by that i mean the local script and the handle has the same parent, the tool, which is located in the players starter pack. Anyways the issue that it only works once and the only way itll work again is if the player dies, i dont know why and the output doesnt tell me anything please help me
local Tool = script.Parent
player = script.Parent.Parent.Parent
local mouse = player:GetMouse()
debounce = true
Tool.Equipped:Connect(function(mouse)
print('tool equipped')
local anima = Instance.new("Animation")
anima.AnimationId = "rbxassetid://885884797"
local humanoid = Tool.Parent.Humanoid
local animationTrack
wait()
mouse.Button1Down:Connect(function()
if debounce == true then
debounce = false
animationTrack = humanoid:LoadAnimation(anima)
animationTrack:Play()
local root = Tool.Parent.HumanoidRootPart
local rhand = Tool.Parent.RightHand
root.CFrame = CFrame.new(root.Position,root.Position + Vector3.new(mouse.hit.lookVector.x,0,mouse.hit.lookVector.z))
wait(0.4)
local orb = Tool.Handle:clone()
orb.CFrame = rhand.CFrame
local bv = Instance.new('BodyVelocity')
bv.MaxForce = Vector3.new(1e8,110000,1e8)
bv.Velocity = mouse.hit.lookVector *75
bv.Parent = orb
orb.Parent = game.Workspace
orb.Size = Vector3.new(2,2,2)
wait(0.2)
orb.Size = Vector3.new(7,7,7)
game.Debris:AddItem(orb,3)
orb.Touched:connect(function(hit)
local ehum = hit.Parent:findFirstChild("Enemy") or hit.Parent:findFirstChild("Humanoid")
if ehum and ehum ~= humanoid then
ehum:TakeDamage(2)
elseif hit.Anchored == true then
for i=1,10 do
local debris = orb:clone()
debris.Size = Vector3.new(0.5,0.5,05)
debris.CFrame = orb.CFrame
debris.ParticleEmitter.LockedToPart = false
debris.BodyVelocity.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
debris.Parent = game.Workspace
game.Debris:AddItem(debris,2)
end
wait(3)
debounce = true
end
end)
end
end)
Tool.Unequipped:Wait()
if animationTrack then -- if the animation track is not nil then stop the animation
animationTrack:Stop()
end
end)
