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

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

Asked by 4 years ago
Edited 4 years ago

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) 
0
Please use Lua Code Block, this isn't easy to read. killerbrenden 1537 — 4y
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 killerbrenden 1537 — 4y
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. 123nabilben123 499 — 4y
0
Use StarterPack hiimgoodpack 2009 — 4y

1 answer

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago

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)
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/ BelGioioso 7 — 4y
0
I'll check it out Filipalla 504 — 4y
Ad

Answer this question