Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I repair this map selection script?

The following code is supposed to select 3 unique maps. I get the following error: bad argument #2 (interval is empty)

local maps = game.ServerStorage.Maps:GetChildren()
local tempmaps = maps
local pad1Map
local pad2Map
local pad3Map

function updateMapViews()
	local first = math.random(1, #tempmaps) --select a map index from tempmaps
	pad1Map = tempmaps[first] --store the map
	table.remove(tempmaps, first) --remove it from the tempmaps table (so that the next maps selected are unique)
	local second = math.random(1, #tempmaps) --ERROR HERE
	pad2Map = tempmaps[second]
	table.remove(tempmaps, second)
	local third = math.random(1, #tempmaps)
	pad3Map = tempmaps[third]
	table.remove(tempmaps, third)
	tempmaps = maps
end

1 comment

0

you dont have any maps lol, that's why it's spitting the error.

1 answer

✓ Accepted answer

math.random spits out that error message when the second argument is 0 i.e. math.random(1, 0)

Check that tempmaps has more than one thing in it, as it appears that once you remove one element on line 10, #tempmaps is 0

1 comment

0

Thanks, I checked out my code again and the culprit appears to be tempmaps = maps. I though the variable value would have been passed by value not reference. Anyways it works now! Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.