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

Why doesn't this weapon giving script work all the time?

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

0

Please use Lua Code Block, this isn't easy to read.

0

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

0

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.

0

Use StarterPack

1 answer

✓ Accepted answer

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)

2 comments

0

You're right, I found out that there was something wrong with one of the scripts in the tools themselves. Do you think you can answer my new question? https://scriptinghelpers.org/questions/94743/

0

I'll check it out

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