Nedd help with running anim not restarting after stopping and moving again

So uhm, im rlly tired right now, and spent way more time on this small issue, and yet idk how to do it. Basically i want this animation to play when player is runnig, and it works, the animations starts and stops when player stops, problem is, when the player restarts after stopping, animation wont play again, i tried with MoveDirection, WalkSpeed, Loops. As i said, it’s prob a small thing, but i’m just tired at this point.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://18758784377'
local PlayAnim = character.Humanoid:LoadAnimation(Anim)

local togleLOL = false




UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.LeftControl and togleLOL == false then
		PlayAnim:Play()
		togleLOL = true
		humanoid.WalkSpeed = 35
	elseif	input.KeyCode == Enum.KeyCode.LeftControl and togleLOL == true then
		PlayAnim:Stop()
		togleLOL = false
		humanoid.WalkSpeed = 8
	end
	
end)

if humanoid.WalkSpeed == 35 and humanoid.MoveDirection.Magnitude > 0 then
	PlayAnim:Play()
end

while wait() do
	if humanoid.WalkSpeed == 35 and humanoid.MoveDirection.Magnitude == 0 then
		PlayAnim:Stop()
	end
	
end

1 Like

ignore the while loop, it works, but its like plays the animation every 0,001 seconds

you should put the outer if function inside the while loop, that way it’s constantly checking if it should start the animation the same way it checks if it should stop

while wait() do
	if humanoid.WalkSpeed == 35 and humanoid.MoveDirection.Magnitude == 0 then
		PlayAnim:Stop()
	end
        if humanoid.WalkSpeed == 35 and humanoid.MoveDirection.Magnitude > 0 then
	        PlayAnim:Play()
        end
end

you mean something like this?

yup. but something that would make it better is if you used an if elseif end block to join the two statements together

yeah, no, thats what i was talking about, i can’t do that or else it will just spam the animation

ok yeah, fixed by adding a bool

thanks anyway for the help

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