How do I stop animation from replaying too quickly?

Hello! I’m making a tool walk animation for my game but the animation replays too quickly, I don’t know why please help.

Heres my code (local script)

local Player = game.Players.LocalPlayer

task.wait(.5)

repeat wait() until Player.Character

local tool = script.Parent

local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

local idleAnim = script.Idle
local walkAnim = script.Walk

local idletrack = humanoid:LoadAnimation(idleAnim)
local walkTrack = humanoid:LoadAnimation(walkAnim)

idletrack.Priority = 0
walkTrack.Priority = 1

local equipped = false

tool.Equipped:Connect(function()
equipped = true

idletrack:Play()

end)

tool.Unequipped:Connect(function()
equipped = false

walkTrack:Stop()
idletrack:Stop()
end)

local running = Enum.HumanoidStateType.Running
local runningNoPhysics = Enum.HumanoidStateType.RunningNoPhysics

game:GetService(“RunService”).RenderStepped:Connect(function()
local currentState = humanoid:GetState()
local moveDirMag = humanoid.MoveDirection.Magnitude

if (currentState == running or currentState == runningNoPhysics) and moveDirMag > 0 and equipped == true then
print(“player is running”)
walkTrack:Play()
end
end)

You could maybe use a boolean variable like canPlay, set it to true, but when the animation plays, set it to false. Then set a wait for how long you would like it to take before the animation can play again and set it to true. It should look something like this.

local canPlay = true
if canPlay == true then
Animation:Play()
canPlay = false
wait(waittimethatyouwant)
canPlay = true
end

Maybe check to see if the animation is already playing, otherwise play the animation and stop when the player isn’t moving.

local Player = game.Players.LocalPlayer

task.wait(.5)

repeat wait() until Player.Character

local tool = script.Parent

local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local idleAnim = script.Idle
local walkAnim = script.Walk

local idletrack = humanoid:LoadAnimation(idleAnim) :: AnimationTrack
local walkTrack = humanoid:LoadAnimation(walkAnim) :: AnimationTrack

idletrack.Priority = 0
walkTrack.Priority = 1

local equipped = false

tool.Equipped:Connect(function()
	equipped = true

	idletrack:Play()

end)

tool.Unequipped:Connect(function()
	equipped = false

	walkTrack:Stop()
	idletrack:Stop()
end)

local running = Enum.HumanoidStateType.Running
local runningNoPhysics = Enum.HumanoidStateType.RunningNoPhysics

game:GetService("RunService").RenderStepped:Connect(function()
	local currentState = humanoid:GetState()
	local moveDirMag = humanoid.MoveDirection.Magnitude

	if (currentState == running or currentState == runningNoPhysics) and moveDirMag > 0 and equipped == true then
		print("player is running")
		if walkTrack.IsPlaying == false then
			walkTrack:Play()
		end
	elseif moveDirMag < 1 then
		walkTrack:Stop()
	end
end)

do

if (currentState == running or currentState == runningNoPhysics) and moveDirMag > 0 and equipped == true and not walkTrack.Playing then
print(“player is running”)
walkTrack:Play()
end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.