I made a animation that punches and hurt people. The animation interrupts when I press the mouse button many times. I want it to only play again if the animation is done.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.Button1Down:connect(function() local animation = Instance.new("Animation") animation.AnimationId="http://www.roblox.com/asset/?id=791758753" local character = Player.Character local anim = character.Humanoid:LoadAnimation(animation) anim:Play() wait(3) character.RightHand.Touched:connect(function(hand) local humanoid = hand.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 hand.Velocity = (hand.CFrame.lookVector) * -50 end end) end)
Bonus Question: How do I hurt a humanoid when the animation is playing and touching the humanoid? When the humanoid touches my hand, it hurts them when i'm not playing the animation. Hope this makes sense.
You can simply check the IsPlaying
state of the AnimationTrack prior to loading and playing it. You're gonna have to make a variable to hold the AnimationTrack.
Also, to make the Touched
event fire you should define it outside of the Button1Down
event.
You may want to add a debounce.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local track --Make a holder for the AnimationTrack repeat wait() until Player.Character local character = Player.Character character:WaitForChild("RightHand").Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 0 hit.Velocity = (hand.CFrame.lookVector) * -50 end end) Mouse.Button1Down:connect(function() if not track and not track.IsPlaying then local animation = Instance.new("Animation") animation.AnimationId="http://www.roblox.com/asset/?id=791758753" local anim = character.Humanoid:LoadAnimation(animation) track = anim; anim:Play() wait(3) end end)