So I have a function to change the walk animation but I'm not sure how to trigger it when a player resets.
here is the function
1 | function addAnimation(player) |
2 | wait( 1 ) |
3 | player.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/? |
4 | id = 1661650912 " |
5 | end |
I'm not sure if there is an event or how I would figure out if a player reset or respawn. Any help is appreciated :)
use PlayerAdded()
and CharacterAdded
. PlayerAdded is triggered in the Players
when someone is added, and CharacterAdded is triggered when the Player spawns.
1 | function addAnimation(character) |
2 | wait( 1 ) |
3 | character:WaitForChild( "Animate" ).walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/? |
4 | id = 1661650912 " |
5 | end |
6 |
7 | game.Players.PlayerAdded:Connect( function (player) |
8 | player.CharacterAdded:Connect(addAnimation) |
9 | end ) |
I'll explain some other changes I did to your script.
I changed player
at line 1 and 3 to character
so it would detect the Character directly instead of having to get it through the player.
I changed Animate
at line 3 to WaitForChild("Animate")
because CharacterAdded fires before the animate script is loaded in. WaitForChild()
will make the function wait until the animation script has loaded.
In the CharacterAdded event
01 | local function addAnimation(player) |
02 | wait( 1 ) |
03 | player.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=1661650912" |
04 | end |
05 |
06 | game.Players.PlayerAdded:Connect( function (Player) |
07 | Player.CharacterAdded:Connect( function (Character) |
08 | addAnimation(Player) |
09 | end ) |
10 | end ) |