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

How do I run a script after player respawns?

Asked by 3 years ago

So I am trying to give the player tools (and change gui text) into their inventory. Since there are some conditions with tools and when the character respawns he doesn't get his tools back. How do I run a script after the players respawns?

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.PlayerGui.SideScreenGUI.Balance.Ribix.Text = player.leaderstats.ribix.Value
    player.PlayerGui.SideScreenGUI.Balance.Bobux.Text = player.leaderstats.bobux.Value
    if player.items.GoodRibixItem.Value == true then
        local gear2 = game.ServerStorage["Good Ribix generator"]
        gear2:Clone().Parent = player:WaitForChild("Backpack")
    else
        local gear = game.ServerStorage["Ribix generator"]
        gear:Clone().Parent = player:WaitForChild("Backpack")
    end
end)

for some reason it does not give any tool at all (there is no error message given) Thanks

1 answer

Log in to vote
0
Answered by 3 years ago

The event PlayerAdded fires only one time when a player joins. Use CharacterAdded on the Player. There's a example:

game.Players.PlayerAdded:Connect(function(player)

    --This event fires everytime the character gets added to the player
    player.CharacterAdded:Connect(function(char)
        --Here you can do whatever you want with the character


    end)

end)
Ad

Answer this question