Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come my script breaks whenever I jump but works fine when I walk?

This script is supposed to make it so that if I try to jump or walk as the animation plays nothing will happen but after the animation is done i can. It works when only walking is involved but whenever i jump before or after the animation i can no longer play the animation. Help?

Player = game.Players.LocalPlayer Tool = script.Parent.Parent Animation = script:WaitForChild("Animation") Enabled = true Tool.Equipped:Connect(function(mouse) mouse.KeyDown:Connect(function(key)

	if not Enabled then return end
	Enabled = false
	
	
	
	if key == "j" then
    local Humanoid = Player.Character.Humanoid
		local animationtrack = Player.Character.Humanoid:LoadAnimation(Animation)
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
		animationtrack:Play()
		wait(2)
		Humanoid.WalkSpeed = 20
	Humanoid.JumpPower = 20


	wait(.5)
		Enabled = true
	end
end)

end)

1 answer

✓ Accepted answer

Check to see if this works

Player = game.Players.LocalPlayer
Tool = script.Parent.Parent
Animation = script:WaitForChild("Animation") 
Enabled = true

Tool.Equipped:Connect(function(mouse)
	mouse.KeyDown:Connect(function(key)
		if not Enabled then return end
	    Enabled = false
	
	    if key == "j" then
	    	local Humanoid = Player.Character.Humanoid
	        local animationtrack = Player.Character.Humanoid:LoadAnimation(Animation)
	    	Humanoid.WalkSpeed = 0
	    	Humanoid.JumpPower = 0
	        animationtrack:Play()
	        wait(2)
	        Humanoid.WalkSpeed = 20
	    	Humanoid.JumpPower = 20
	
	    	wait(.5)
	    end
	
		Enabled = true --//Took it outside the if statement so if the key isn't j, it can actually reset.
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.