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

bad argument #2 to 'random' (interval is empty)??

I have a issue with my script. I need help!!!

for _, player in pairs(activecontestants) do
		if player then
			awardpoints(player, 1)
			if player.Character then
				local humanoid = player.Character:FindFirstChild("Humanoid")
				if humanoid then
					humanoid:UnequipTools()
				end
			end

			local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
			player.Character:MoveTo(randomspawn.Position)

			local backpack = player:FindFirstChild("Backpack")
			if backpack then
				backpack:ClearAllChildren()
			end
		end
	end

The error is on line 11. This is a part in a long script and it is going to teleport players in my game back to the lobby and get players points for surviving the game and get rid of any tools when they spawn into lobby

Hope you can help :D

6 comments

0

Can we get more code?

0

sure

0

Any chance we can see the full error, what line it errored on. As well as further explanation as to what the script is is supposed to do in the first place.

0

How are you getting the value for lobbyspawns?

0

this is like the main script for the game so its like 484 lines. Do you want me to post the whole script??

0

No, but if it's erroring that the second argument is bad then the table for lobbyspawns is not being utilized correctly.

1 answer

local randomspawn = lobbyspawns[math.random(#lobbyspawns)]

That might solve your issue, kind of. When math.random spits out error messages about intervals, it's normally because arg #2 is smaller than arg #1, which will happen when #lobbyspawns is 0 or 1. You might want to check the length of your table with a print because this could imply some other issue in your code.

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