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 6 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

function addAnimation(player)
    wait(1)
player.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/? 
    id=1661650912"
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 :)

2 answers

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

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

function addAnimation(character)
    wait(1)
character:WaitForChild("Animate").walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/? 
    id=1661650912"
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(addAnimation)
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.

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

In the CharacterAdded event

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

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        addAnimation(Player)
    end)
end)

Answer this question