Invalid argument #2 to 'random' (interval is empty)

	local items = game.ServerStorage.Shells:GetChildren()
		local randomItem = items[math.random(1, #items)]

it errors on that line idk why

Full script :

local amn = 80
local curamn = 0

while wait(.1) do
	if curamn == amn then
		script:Remove()
	else
		curamn = curamn + 1
		local items = game.ServerStorage.Shells:GetChildren()
		local randomItem = items[math.random(1, #items)]
		randomItem.Parent = workspace
		randomItem.Name = "Shell"
		randomItem.Position = Vector3.new(math.random(-1495.75,-179.25),0,math.random(24.25,1121.75))
	end
end

Can you show a screenshot about the error?

image

nvm i edited it a bit and this worked

local amn = 80
local curamn = 0
local items = game.ServerStorage.Shells:GetChildren()


while wait(.1) do
	local randomItem = items[math.random(1, #items)]
	if curamn == amn then
		script:Remove()
	else
		curamn = curamn + 1
		randomItem.Name = "Shell"
		randomItem.Position = Vector3.new(math.random(-1495.75,-179.25),0,math.random(24.25,1121.75))
		randomItem.Parent = workspace
	end
end
1 Like

This will only return integers between these points, not decimals. If you want decimals, you should use the Random library:

local amn = 80
local curamn = 0
local items = game.ServerStorage.Shells:GetChildren()

local rand = Random.new(); -- create a new Random object
while wait(.1) do
	local randomItem = items[math.random(1, #items)]
	if curamn == amn then
		script:Remove()
	else
		curamn = curamn + 1
		randomItem.Name = "Shell"
		randomItem.Position = Vector3.new(rand:NextNumber(-1495.75,-179.25),0,rand:NextNumber(24.25,1121.75))
		randomItem.Parent = workspace
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.