Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A function to change the animation everytime somebody resets or respawns?

Asked by 7 years ago

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

1function addAnimation(player)
2    wait(1)
3player.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?
4    id=1661650912"
5end

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 :)

2 answers

Log in to vote
1
Answered by
ax_gold 360 Moderation Voter
7 years ago

use PlayerAdded() and CharacterAdded. PlayerAdded is triggered in the Players when someone is added, and CharacterAdded is triggered when the Player spawns.

1function addAnimation(character)
2    wait(1)
3character:WaitForChild("Animate").walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?
4    id=1661650912"
5end
6 
7game.Players.PlayerAdded:Connect(function(player)
8    player.CharacterAdded:Connect(addAnimation)
9end)

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.

0
Thank you kind person this was very explanatory :) 4d61736f6e 59 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

In the CharacterAdded event

01local function addAnimation(player)
02    wait(1)
03    player.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=1661650912"
04end
05 
06game.Players.PlayerAdded:Connect(function(Player)
07    Player.CharacterAdded:Connect(function(Character)
08        addAnimation(Player)
09    end)
10end)

Answer this question