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

How do I make this script repeat its self when a player dies?

Asked by
ali7682 17
6 years ago

So basically, this script gives the owner (me) a tool from the lightning section, in there is a model called OwnerTools and a tool. The script works fine but.. when ever I die, I just lose the item and I have no idea how to fix this. The script:

game.Players.PlayerAdded:connect(function(player)
    if player.userId == game.CreatorId then 
        player.CharacterAdded:wait()
        for i,v in pairs(game.Lighting.OwnerItems:getChildren()) do
        v:Clone().Parent = player.Backpack 
        end
    end 
end)

-Thanks

2 answers

Log in to vote
0
Answered by
hiccup111 231 Moderation Voter
6 years ago
Edited 6 years ago

See the roblox Wiki - CharactedAdded (event of the Player object) http://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAdded

Ad
Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
6 years ago

Okay ill help you out, so you could use a player died function like this

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            -- code here
        end)
    end)
end)

So this is how your code would look

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            if player.userId == game.CreatorId then 
                        for i,v in pairs(game.Lighting.OwnerItems:getChildren()) do
                        v:Clone().Parent = player.Backpack 
        end)
    end)
end)

Answer this question