Need help with error

for some reason im getting invalid argument #2 to ‘random’ (interval is empty)
happens on localRadmap line

function CountVotes()

local SoFar = {nil,0}
local AllTab = {}
local RadMap = AllTab[math.random(1,#AllTab)]

getVotes = script.Vote:getChildren()
for gv=1, #getVotes do
	if getVotes[gv].Value > SoFar[2] then
		SoFar[1],SoFar[2] = getVotes[gv].Name,getVotes[gv].Value	
	end	
end

for gv=1, #getVotes do
	if getVotes[gv].Value == SoFar[2] then
		table.insert(AllTab,getVotes[gv].Name)	
	end
end

RadMap = Maps[RadMap]
PreviousMap = RadMap.Name
RandomMap = RadMap
print("Voting is over, map selected")
pcall(function()
	getPlayers = Players:getChildren()
	for gp=1, #getPlayers do
		getPlayers[gp].PlayerGui.VoteGui.Vote.Visible = false
		getPlayers[gp].PlayerGui.VoteGui.Help.Visible = false
		getPlayers[gp].PlayerGui.VoteGui.Script.VoteBool.Value = true	
	end	
end)

end

This should’ve been painfully obvious.

Since AllTab is an empty table, its length will be zero, which means that you’re giving the math.random function an upper-bound that’s smaller than the lower-bound, which makes no sense and hence the error

Im a noob at it i know sorry lol. But for some reason im still getting the same error again

It would be nice if you actually told me what you changed/tried that still didn’t work :upside_down_face:

only changed local SoFar. Changed it to {} instead of {nil,0}

changing it to an empty table is what’s causing the original problem? What was that line of code supposed to do anyways

I might have figured it out. There was never originally an issue so im trying the 1st copy of it that worked and seeing if it fixes it. If so ill answer back with what my issue was

1 Like

function CountVotes()

getVotes = script.Vote:getChildren()

local SoFar = {nil,0}

for gv=1, #getVotes do
	if getVotes[gv].Value > SoFar[2] then
		SoFar[1],SoFar[2] = getVotes[gv].Name,getVotes[gv].Value	
	end	
end

local AllTab = {}
for gv=1, #getVotes do
	if getVotes[gv].Value == SoFar[2] then
		table.insert(AllTab,getVotes[gv].Name)	
	end
end

local RadMap = AllTab[math.random(1,#AllTab)]

RadMap = Maps[RadMap]
PreviousMap = RadMap.Name
RandomMap = RadMap
print("Voting is over, map selected")
pcall(function()
	getPlayers = Players:getChildren()
	for gp=1, #getPlayers do
		getPlayers[gp].PlayerGui.VoteGui.Vote.Visible = false
		getPlayers[gp].PlayerGui.VoteGui.Help.Visible = false
		getPlayers[gp].PlayerGui.VoteGui.Script.VoteBool.Value = true	
	end	
end)

end

I figured it out. Thank you for the help tho. Had the locals in wrong spots thats all
:man_facepalming:

1 Like