Here is my script:
game.ReplicatedStorage.RandomizeItems.OnServerEvent:Connect(function() local function choose(tab) local n = math.random(1, #tab) local obj = tab[n] return obj end
local Amount = math.random(2,9) if script.Parent:findFirstChild("Torso") then for i=1, Amount do local LocalPlr = game.Players:FindFirstChild(script.Parent.Name) local Item = choose(game.ReplicatedStorage.BackpackItems:GetChildren()) wait(1.5) Item:Clone() Item.Parent = LocalPlr.Backpack end end
end)
It goes in the "StarterCharacterScripts" and is a server script.
It keeps getting this error:
RandomItems:3: bad argument #2 to 'random' (interval is empty)
Can you help?
(I cant find any ways to fix my code on my own or the internet)
Hey this is what you're looking for.
local rs = game:GetService("ReplicatedStorage") function getRandomTool(player) for i = 1, math.random(1,9) do local item = rs.BackpackItems:GetChildren()[math.random(1, #rs.BackpackItems:GetChildren())]:Clone() item.Parent = player.Backpack end end game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function() getRandomTool(plr) end) end)
I'm guessing this is because of local n = math.random(1, #tab)
. I can't see your variables but I'm almost sure of this. Try changing it to a number instead of a variable.