Is there a way to make this animation script work in a public game?

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?

Hey man, thx for the reply.

This was already done, here is how the model looks like if you wanna see if there’s a mistake in there
image

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!

1 Like

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?

Hey man, just went and did some digging, and found that while in-game, using the console, this error came up.


This error came up on “Server” and not “client”. Also, the error isn’t present while in studio.

This means that they ID shown is not accessible by the game. Are you sure it is a valid ID, that is also usable by that game in particular?

That is quite strange that the animation works in studio, but not in game.

I think so? swinging anim - Roblox
This is the ID, made by me. However, the game is in a group.
Hope this helps.

You need to upload the animation to the group for group games to be able to access the animation.

You need to upload the Animation as a group asset as I stated earlier. Groups don’t have permissions to steal animations off a user’s profile.

Re-upload the animation to the group, and the problem should be solved.

Ooo, I thought cause I made it in the game, that it would be made into a group asset. How do I transfer it to the group?

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.

Omg, you’re correct. I remember it asking who the owner would be, I think this solves it. Thank you so much!

1 Like