Animation Loop not working

  1. What do you want to achieve?
    I would like to have the animation loop consistently when the tool is equipped.
  2. What is the issue?
    When looped in a local script it only loops locally while when looped in a global script it only plays once.
  3. What solutions have you tried so far?
    I’ve tried placing it into a global script and messing with the different priorities. I looked around for any solutions but couldn’t find anything discussing setting Looped to True making the Animation only run looped locally. I have also tried setting it to Looped in the Anim Editor. I have tried running the animation on the client and serverside. This caused the animation to run well on both client and serverside but not other clients.
  4. Details
    It’s supposed to be an idle animation for a simple punching tool. It seems like this is the reason for the problem: AnimationTrack.Looped Does Not Replicate - Platform Feedback / Engine Bugs - Roblox Developer Forum but I can’t figure out a way around this.
    Code is down here from when I tried it on client side:
hum = script.Parent.Parent.Humanoid
	local attack = hum:LoadAnimation(script.idle)
	--attack.Looped = true
	attack.Priority = Enum.AnimationPriority.Idle
	attack:Play()

Hey!

Humanoid:LoadAnimation() has been deprecated for a while. I’m also not sure how to load animations, I can’t get them to work either.

(First Post)

1 Like

This function is deprecated, load your animation on the animator

1 Like

I’ve tried loading animations with the animator but it didn’t seem to work either, can you show me an example of how the script’s constructed? This is what I did;

-- LocalScript
local isDancing = (false)
local Animation = (script.Parent:WaitForChild("Animation"))

local function onEquipped()
	local Player = game:GetService("Players").LocalPlayer
	local Mouse = Player:GetMouse()
	Mouse.Button1Down:Connect(function()
		if isDancing == (true) then
			isDancing = (false)
			script.Parent.DanceRemote:FireServer("StopDance")
		elseif isDancing == (false) then
			isDancing = (true)
			script.Parent.DanceRemote:FireServer("Dance")
		end
		print(isDancing)
	end)
end

local function onUnequipped()
	if isDancing == (true) then
		isDancing = (false)
		script.Parent.DanceRemote:FireServer("StopDance")
	end
end

script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(onUnequipped)
-- ServerScript
script.Parent.Parent.DanceRemote.OnServerEvent:Connect(function(Player, Type)
	local isDancing = (false)
	if Type == ("Dance") then
		isDancing = (true)
	elseif Type == ("") then
		isDancing = (false)
	end
	local Loop = coroutine.wrap(function()
		while true do
			wait()
			if isDancing == (true) then
				Player.Character.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Parent.Parent.Animation)
			end
		end
	end)
end)

I believe your issue is that you loaded the animation but you never played it:

if isDancing == (true) then
   local animator = Player.Character.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Parent.Parent.Animation)
   animator:Play()
end

I’m the biggest idiot, let me try and let you know how it goes.

Doesn’t work either for some reason, probably because I did it in the server script. Let me rewrite the entire script locally and try to make a local animation instance instead of having a variable to a server animation instance.

Thank you for the update on that. I’ve changed the code to load to the animator although this has not changed the output. The problem of Looping is still an issue. I have also tried using a while loop which has had the same effect as setting Looped to True.

Wait so you can play the animation but you can’t make it loop?

Indeed. The problem with your code might be that you aren’t giving the Animation enough time to loop correctly.
Try adding a wait that’s the length of the animation or longer.

I solved the issue. Setting the Animation priority(Action) inside the Animation editor and the same with setting Looped to True allowed the animation to be seen on client, other clients, and the server itself.