Player won't get items after respawning, any help?
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.
03 | for j,plr in pairs (plrs) do |
08 | plr.Character.Humanoid.Died:Connect( function () |
09 | wait(game.Players.RespawnTime) |
10 | local weapons = game.ServerStorage:WaitForChild( "weapons" ) |
12 | local melee = weapons:WaitForChild( "Melee" ):GetChildren() |
13 | local ranged = weapons:WaitForChild( "Ranged" ):GetChildren() |
14 | local misc = weapons:WaitForChild( "Misc" ):GetChildren() |
17 | local chosenMelee = melee [ math.random( 1 ,#melee) ] :Clone() |
18 | local chosenRanged = ranged [ math.random( 1 ,#ranged) ] :Clone() |
19 | local chosenMisc = misc [ math.random( 1 ,#misc) ] :Clone() |
21 | chosenMelee.Parent = plr.Backpack |
22 | chosenRanged.Parent = plr.Backpack |
23 | chosenMisc.Parent = plr.Backpack |
25 | print (plr.Name,chosenMelee.Name,chosenRanged.Name,chosenMisc.Name) |
31 | print (plrs [ j ] .Name.. ' was removed' ) |