Animation on Spawn?

Hello! I’m a new developer who just started learning a lot about scripting.
Currently I have a well made game but I just stumbled upon a really basic problem I couldn’t solve. Again I’m still learning but I have no idea how to add it.

This may be easy for you to add but I don’t know how to make it. I’m trying to make an animation that I made start when an NPC loads into a game.

I tried to search on the Dev Forum, look up YouTube Tutorials or anything I could use to find the answer to my simple question, but no, I didn’t find anything.

Simple feedback would really help. I hope soon I could master scripting and make a great game everyone can enjoy, but that reality hasn’t evolved yet.

3 Likes

I’m not a programmer and not sure, what about using PlayerAdded:Connect() function?

4 Likes

Thanks I’ll try. I’ll edit my comment to tell if it works or not.
Edit: I don’t think it worked

You will need CharacterAdded and play the animation each time the event runs.

1 Like

Thanks I’ll be sure to try it out.

game.Players.CharacterAdded:Connect(function(char)
-- do stuff with animation
end)

There is a little kickstart for you.

If I was any help, mark me as a solution for other people who might need help in the future when they look here.

1 Like

Try this :

game.Players.PlayerAdded:Connect(function(plr)--Player joins
    plr.CharacterAdded:Connect(function(char)--character is added
          local hum = char:WaitForChild("Humanoid")
          local anim = --Put your animation's location here Example : game.ReplicatedStorage.Animation 
          hum:LoadAnimation(anim)
          anim:Play()
    end)
end)
7 Likes

That would only work when they first join.

?
The Character added event fires every time a character spawns. So yes the animation will play everytime the character spawns.

Yeah; but you have a playeradded as well, so the script will only run when a player has joined the server

Incorrect. Test it if you want.

I don’t wanna flood this post with irrelevant comments, if you want to prove me wrong or something simply try it. I am here to help.

1 Like

Basically, only the first time they spawn it will work

I am too, just attempting to point something out.

To Correct you,

This is incorrect, there’s no such thing as game.Players.CharacterAdded, you have to get the player instance from PlayerAdded event.

2 Likes

huh

could be my bad then

If it is, I apologise

Well I’m just looking for a script that plays an animation for a certain NPC everytime they load into the game.

1 Like

The way I do it is just game.Workspace.ChildAdded, then check if it’s a playet

1 Like