Heyo, I created a little looped NPC animation that would be constantly playing. The animation works fine, it plays well in Studio while testing. However, when I put it into a public game, it just doesn’t play.
Here is the script, I got it from a video online.
while true do
wait(3)
local hum = script.Parent.Humanoid
local anim = hum:LoadAnimation(script.Parent.Animation)
anim:Play()
end
Now, the script seems way too simple. I suspected it has something to do with new players joining the game, causing it to just not play…
Please lmk of what is wrong in the script.
Thanks!
There is nothing wrong with that script syntax wise that I can see. It may be a issue with how you are using it.
The script requires a Animation object named “Animation” to be present under the same parent as the Script. Make sure you have created the Animation object, and are not running the Script by itself.
Secondly, make sure that the game you use it in, has permissions to use the animation ID you have in the Animation object. The game and the animation must be created by you, not by a group.
Also, if you are running the script from inside the character, you may want to use WaitForChild to yield for the Humanoid to load.
local hum = script.Parent:WaitForChild("Humanoid")
This also goes for the Animation.
local anim = hum:LoadAnimation(script.Parent:WaitForChild("Animation"))
If none of these thoughts help solve the problem, can we get more information about the context of the script, and where it is being used?
This was already done, here is how the model looks like if you wanna see if there’s a mistake in there
As for the second question, I am pretty sure the ID was made in the game, which is connected to my group. So, how would I enable animations to be allowed in-game.
And for the last question, when you say running inside the character, do you mean the player of the game? If so no, the animation is playing on another NPC, and said NPC is just swinging their arm in a loop. But I will add that to the script, thanks!
There is no way of enabling animations for a game. You just need to make sure that the animation wasn’t created by someone other than yourself. Sorry if I made that unclear.
Try using WaitForChild(), and see if that fixes the issue.
Also, are you getting any errors in the output/console when you play the game?
Import the animation onto a Dummie rig( creatable with the Rig Builder tool ) using the animation editor. Then export it while setting the creator to the group, instead of yourself.
After that you can just grab the new AssetId, and you are good to go.