If ItemLimit is equal to 5, then it would spawn 10 items. The spawning function isn’t causing the problem though. I tried putting the third argument of the for loop to 2 to fix it, but I realized it wouldn’t work on odd numbers.
local function spawnItems(area, amount)
for i = 1, amount, 1 do
local xVectorRandom = area.CFrame.RightVector * area.Size.X * (math.random(-50, 50) / 100)
local yVectorRandom = area.CFrame.UpVector * area.Size.Y
local zVectorRandom = area.CFrame.LookVector * area.Size.Z * (math.random(-50, 50) / 100)
local spawnPosition = area.CFrame + xVectorRandom + yVectorRandom + zVectorRandom
local clonedItem = items[ChooseItemBasedOnRarity(area.ItemsToSpawn:GetChildren())]:Clone()
clonedItem.PrimaryPart = clonedItem:FindFirstChild("Primary")
clonedItem:SetPrimaryPartCFrame(spawnPosition)
clonedItem.Parent = area.ItemsInArea
end
end
local function startSpawns()
for i, area in pairs(workspace.Areas:GetChildren()) do
spawnItems(area, area.ItemLimit.Value)
end
end
startSpawns()
local function spawnItems(area, amount)
for i = 1, amount do
local xVectorRandom = area.CFrame.RightVector * area.Size.X * (math.random(-50, 50) / 100)
local yVectorRandom = area.CFrame.UpVector * area.Size.Y
local zVectorRandom = area.CFrame.LookVector * area.Size.Z * (math.random(-50, 50) / 100)
local spawnPosition = area.CFrame + xVectorRandom + yVectorRandom + zVectorRandom
local clonedItem = items[ChooseItemBasedOnRarity(area.ItemsToSpawn:GetChildren())]:Clone()
clonedItem.PrimaryPart = clonedItem:FindFirstChild("Primary")
clonedItem:SetPrimaryPartCFrame(spawnPosition)
clonedItem.Parent = area.ItemsInArea
end
end
local function startSpawns()
for i, area in pairs(workspace.Areas:GetChildren()) do
spawnItems(area, area.ItemLimit.Value)
end
end
startSpawns()