I have three different punching animations called animation1 animation2 and animation3 in the script. I need someones help trying to allow the** script to do one punch then press f again in a period of like 0.5 seconds** (after the first one finished)** to activate a second one and then another one in another period of 0.5 seconds after the second one finished**. I was thinking else return might work but it didn't. Also, if they dont press f inbetween after the other one finished then it to cancel out. Also i** dont want it to keep restarting the punch by spamming f**. I know this sounds a lot but this is out of my area of thinking. Any help would be appreciated. Thanks.
CanDoDmg = true -- If the player can do damage
Keybind1 = "f"
Keybind2 = "f"
Keybind3 = "f" -- Keybind to activate the punch
dmg = 20 -- How much damage the player takes
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.KeyDown:Connect(function(key)
if key == Keybind1 then
local anim = script.Parent.Humanoid:LoadAnimation(script.Animation1)
anim:Play()
wait()
script.Parent.RightHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and CanDoDmg == true then
hit.Parent.Humanoid:TakeDamage(dmg)
CanDoDmg = false
wait(1)
CanDoDmg = true
mouse.KeyDown:Connect(function(key)
if key == Keybind2 then
local anim = script.Parent.Humanoid:LoadAnimation(script.Animation2)
anim:Play()
wait()
script.Parent.RightHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and CanDoDmg == true then
hit.Parent.Humanoid:TakeDamage(dmg)
CanDoDmg = false
wait(1)
CanDoDmg = true
mouse.KeyDown:Connect(function(key)
if key == Keybind3 then
local anim = script.Parent.Humanoid:LoadAnimation(script.Animation3)
anim:Play()
wait()
script.Parent.RightHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and CanDoDmg == true then
hit.Parent.Humanoid:TakeDamage(dmg)
CanDoDmg = false
wait(1)
CanDoDmg = true
end
end)
end
end)

2 comments
Oh, and you might also want to do something about the Touched event that is connected to the right hand. Right now it can stack, so the fifth time you punch somebody, it will deal 100 damage.
Hey thanks for the script it all seems good in the code yet when i run it, it says Animation1 is not a valid member of script yet it is in the script? This might be a roblox error as nothing appears wrong in your script and there are no red bits. Ill have another look into it