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

Player won't get items after respawning, any help?

Asked by 3 years ago

So, I'm making a randomizer type game where you get random items after every time you die, but the main issue is the the point of the game where you get random items. Everything works great, just except for when you respawn to get your items. When you respawn, the game will either crash, or give you 60+ items where you're meant to only get three. I've tried checking the amount of tools a player in the table has in their backpack, and so many other attempts that I just completely forgot about. And there aren't any errors in the output.

01for x = 300,0,-1 do
02 
03    for j,plr in pairs(plrs) do
04        if plr then
05            if plr.Character then
06                -- they in the game
07 
08                plr.Character.Humanoid.Died:Connect(function()
09                    wait(game.Players.RespawnTime)
10                    local weapons = game.ServerStorage:WaitForChild("weapons")
11 
12                    local melee = weapons:WaitForChild("Melee"):GetChildren()
13                    local ranged = weapons:WaitForChild("Ranged"):GetChildren()
14                    local misc = weapons:WaitForChild("Misc"):GetChildren()
15 
View all 44 lines...
0
You could just clone the items into both backpack and startergear so it would just automatically place the items into backpack on death... tightanfall 110 — 3y
0
the point would be to get random items and not the same ones that you had before jorcorrs 76 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

I see your problem, one solution that I have in mind is that you can make a folder(parented wherever is best for you) with tools(in your case, you would create 3 folders) and get it's children in the script.

Using the event of Player called CharacterAdded, you can do something like this(I'll be using only 1 folder)

01local getTools = game:GetService('ReplicatedStorage').ToolsFolder:GetChildren()
02 
03game:GetService('Players').PlayerAdded:Connect(function(plr) -- gets player from PlayerAdded
04 
05local BP = plr.Backpack
06 
07plr.CharacterAdded:Connect(function() -- events fires when character is added
08local clonedTool = getTools[math.random(1, #getTools)]:Clone() -- the selected tool is cloned
09 
10clonedTool.Parent = BP
11end)
0
i actually fixed it, I'll accept your answer anyway though jorcorrs 76 — 3y
Ad

Answer this question