What do you want to achieve?
I would like to have the animation loop consistently when the tool is equipped.
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.
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.
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
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.
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.