Im trying to make items spawn randomly in certain areas every couple of seconds, the item will be picked randomly, with a chance, and so will its location. But i keep getting an error at 5: invalid argument #2 to ‘random’ (interval is empty), and im not sure how to fix it.
while true do
local locations = workspace.Map.Itemspawns:GetChildren()
local itemfolder = game.ReplicatedStorage.Items:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
item.Parent = math.random(#locations, 1)
item.Handle.Anchored = true
item.Handle.CFrame = item.Parent.CFrame
wait(5)
end
It seems like you are parenting the item to a number, not an instance.
I’m guessing you want something like this
while true do
local locations = workspace.Map.Itemspawns:GetChildren()
local itemfolder = game.ReplicatedStorage.Items:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
item.Parent = locations[math.random(1, #locations)]
item.Handle.Anchored = true
item.Handle.CFrame = item.Parent.CFrame
wait(5)
end