Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.