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

So my animation keeps looping when I click the button to punch, why is this?

I'm not the best at scripting but I thought that I had gotten the hang of the basics and yet now I for some reason am unable to fix this. This is code for punching for my game. Here is the code:

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")
local Check = 0
local Enable = true
local idle = script.Idle

Tool.Equipped:Connect(function()
	local idleey = Humanoid:LoadAnimation(idle)
	idleey:Play()
	Tool.Unequipped:Connect(function()
		idleey:Stop()
	end)
end)

Tool.Activated:Connect(function()
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
if Enable == true then
	Enable = false
	if Check == 0 then
		humanoid:LoadAnimation(script.Anim01):Play()
		script.Parent.Combo.C0:FireServer(Char:FindFirstChild("LeftHand"))
		script.Swing:Play()
		wait(0.4)
		Check = 1
		Enable = true
		Humanoid:LoadAnimation(script.Anim01):Stop()
	else if Check == 1 then
		humanoid:LoadAnimation(script.Anim02):Play()
		script.Parent.Combo.C1:FireServer(Char:FindFirstChild("RightHand"))
		script.Swing:Play()
		wait(0.4)
		Check = 0
		Enable = true
		Humanoid:LoadAnimation(script.Anim02):Stop()
	end
	end
 end
end)

while wait(3) do
	if Check == 1 then
		Check = 0
	end
end

all help is appreciated.

1 comment

0

:LoadAnimation creates a new animation, on line 22 you create an animation and play it and on line 28 you are creating another animation and stopping it, but this does not affect the other animation, put animation on line 22 into variable so you reuse it and same for lines 30, 36.

1 answer

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