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)
Are you sure? This has worked every time I have reset my Character, I changed the code slightly tho
local Players = game:GetService("Players") local Lighting = game:GetService("Lighting") local Weapons = Lighting.Weapons Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) Weapons:GetChildren()[math.random(1,#Weapons:GetChildren())]:Clone().Parent = Player.Backpack end) end)