I'm trying to make a script that gives the player a weapon every time they die. And it works sometimes, but other times it gives them nothing when they respawn. Here's the script:
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
repeat wait() until p:FindFirstChild("Backpack")
game.Lighting.Weapons:GetChildren()[math.random(1, #game.Lighting.Weapons:GetChildren())]:Clone().Parent = p.Backpack
end)
wait(2)
end)

4 comments
Please use Lua Code Block, this isn't easy to read.
If you need help on how to do that, hover over your name at the top right and press help and click on "How To Post Good Questions and Answers" - https://scriptinghelpers.org/help/how-post-good-questions-answers
Is it where whenever a player dies they get a brand new weapon? I didn't find anything where the server can detect whenever a player dies but it seems like you need the player itself to detect whenever they die.
Use StarterPack