Hey guys. I’ve posted about this before but I’ve gotten more info on it. I’m working on a PVP game where you are supposed get 4 random gears when you spawn - each one being from a different gear folder. But, I’ve been having an issue where after you die a few times, you get 2 gears, 3 gears, 0 gears, you get it. I’ve tried making the spawn time to instant to see if that’d help and it didn’t help at all. Again, I’ve posted this on here before too and all the solutions I’ve gotten have stopped working. Here’s the script that I use for the random gear giving:
wait(0.1)
local serverStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local Folder1 = serverStorage:WaitForChild("Weapons"):GetChildren()
local Folder2 = serverStorage:WaitForChild("Weapons1"):GetChildren()
local Folder3 = serverStorage:WaitForChild("Other"):GetChildren()
local Folder4 = serverStorage:WaitForChild("Social"):GetChildren()
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local randomGear1 = Folder1[math.random(2, #Folder1)]
local randomGear2 = Folder2[math.random(1, #Folder2)]
local randomGear3 = Folder3[math.random(1, #Folder3)]
local randomGear4 = Folder4[math.random(1, #Folder4)]
randomGear1.Parent = player.Backpack
randomGear2.Parent = player.Backpack
randomGear3.Parent = player.Backpack
randomGear4.Parent = player.Backpack
end)
end)
And here’s the error I see in console when it gives me less gears than intended:
Does anybody have an idea on how to fix this?