Animation not looping while looped

I made a sliding animation for a football (soccer) game that is meant to be looped. It’s only one keyframe, that’s why I looped it, so that I can stop it whenever I want.

When my character walks, it works perfectly:

But when I am standing still, it bugs out or something:

This happened just now and worked perfectly fine before.
This is my script I use to make the player slide, no other scripts involved:

local UIS = game:GetService("UserInputService")
local char = script.Parent

local slideAnim = script:WaitForChild("SlideAnimation")


local keybind2 = Enum.KeyCode.Space --key code
local canslide = true

local boughtspeed = false

local function slide()
	if char:WaitForChild("Slowed").Value == false then

		if char.Humanoid.WalkSpeed == 30 then
			boughtspeed = true
		end

		canslide = false
		game.ReplicatedStorage.isSliding:FireServer()
		local playAnim = char.Humanoid.Animator:LoadAnimation(slideAnim)
		playAnim.Looped = true
		playAnim:Play()



		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1)*37500
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector*75
		slide.Parent = char.HumanoidRootPart

		for count = 1,8 do
			wait(0.1)
			slide.Velocity*=0.8
		end

		playAnim:Stop()
		slide:Destroy()
		if char.Slowed.Value == true then
			char.Humanoid.WalkSpeed = 0	
		end

		game.ReplicatedStorage.isSlidingDone:FireServer()

		wait(5)
		canslide = true
	else
		return
	end
end

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end

	if input.KeyCode == keybind2 then
		slide()
	end
end)

As you can see, I have added a function called slide(). The script inside the function is exactly the same as to what was where this function is called now:

if input.KeyCode == keybind2 then
		slide()
end

This is very weird, as I have made no changes to the way the sliding works, only added it in a function. It’s also weird that it only works when moving and not when standing still.

Thank you for reading, please help me if you know the issue.

Can you tell me on what the animation priority is set on?

Maybe it’s because if you’re not moving your charecter’s Walkspeed == 0 so maybe change that

The Humanoid’s WalkSpeed Property stays the same even when you are not moving. You can detect if the player is moving using Humanoid.MoveDirection.

Thank you, I was able to find the issue from this.

The animation was set to Core, which is the lowest priority I think, so that means the Idle animations will override it, and that is why it wasn’t playing. I still have no idea why this only happened when I made a function in my script, but I’m glad I found the issue.

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