Hello, recently I've run into a problem where a script I made that plays an idle animation only plays in studio, which is technically FE turned off, and not in the normal play. I don't know what's wrong. Here is the script:
local character = script.Parent local humanoid = character.Humanoid local prevanim = nil function playAnim(animation) if prevanim ~= nil then prevanim:Stop() end prevanim = humanoid:LoadAnimation(animation) prevanim:Play() end playAnim(script.idle.IdleAnim)
Any help/feedback would be great! Thanks!
Hi!
FilteringEnabled actually doesn't happen to be the issue here. In test mode, it is offline and is quicker to load. But in the actual game, it is online and takes longer to load. Judging by the variables I am going to assume that this is in StarterCharacterScripts. Since the real game takes longer to load than in test mode, the objects that you set as values may not exist yet, breaking the script.
To fix this, you can either add :WaitForChilld() instance or a repeat loop. Since we are waiting for both the character and the animation to load, I will be adding a repeat loop for both.
repeat wait() until script.Parent and script.idle.IdleAnim --This will halt the script until the character and the animation is loaded. local character = script.Parent local humanoid = character.Humanoid local prevanim = nil function playAnim(animation) if prevanim ~= nil then prevanim:Stop() end prevanim = humanoid:LoadAnimation(animation) prevanim:Play() end playAnim(script.idle.IdleAnim)
Another recommendation is to make sure that this is inside a Local Script, since it will run client-connected Lua code in the descendant of a Character model.