Aight so the animation when I click plays when i press but the hit the :TakeDamage(60) happens right away when I don't click like if I just get the Handle(The handle is a square part ) it does damage right away how can i make it so that only if i click it does damage
tool = script.Parent Handle = tool:WaitForChild("Handle") player = game.Players.LocalPlayer mouse = player:GetMouse() Animation = tool:WaitForChild('Anime') AnimationTime = true tool.Equipped:Connect(function() print(tool) end) tool.Activated:Connect(function() if AnimationTime then AnimationTime = false local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation) AnimationPlay:Play() wait(1) AnimationTime = true end end) Handle.Touched:Connect(function(hit) debounce = false if hit and tool.Activated then Humanoid = hit.Parent:FindFirstChild('Humanoid') if Humanoid then Humanoid:TakeDamage(60) wait(1) end end end)
This is because you didnt make a boolean
for the Touched
event when it should fire, so it just fires outright and putting the Activated
event in the if statement wont do anything. You can fix this by just using a boolean
like what i said.
local tool = script.Parent local Handle = tool:WaitForChild("Handle") local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Animation = tool:WaitForChild('Anime') local AnimationTime = true local canTouch = false tool.Equipped:Connect(function() print(tool) end) tool.Activated:Connect(function() if not AnimationTime then AnimationTime = false local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation) AnimationPlay:Play() canTouch = true AnimationPlay.Stopped:Wait() AnimationTime = true canTouch = false end end) Handle.Touched:Connect(function(hit) local Humanoid = hit.Parent:FindFirstChild('Humanoid') if Humanoid and canTouch == true then Humanoid:TakeDamage(60) end end end)