Vote system picks 2 maps

I have a map voting system for my game and when someone picks the second option it enables the map script like it should but it also enables another random one. Does anyone know what the problem might be? Here’s the script:

	if workspace.Maps.Base.Votes.Value > workspace.Maps.City.Votes.Value and workspace.Maps.Prison.Votes.Value then
		workspace.Maps.Base.Story.Enabled = true
		workspace.Maps.City.Story.Enabled = false
		workspace.Maps.Prison.Story.Enabled = false
		chosenMap.Value = "Base"
	end
	if workspace.Maps.City.Votes.Value > workspace.Maps.Base.Votes.Value and workspace.Maps.Prison.Votes.Value then
		workspace.Maps.City.Story.Enabled = true
		workspace.Maps.Prison.Story.Enabled = false
		workspace.Maps.Base.Story.Enabled = false
		chosenMap.Value = "City"
	end
	if workspace.Maps.Prison.Votes.Value > workspace.Maps.City.Votes.Value and workspace.Maps.Base.Votes.Value then
		workspace.Maps.Prison.Story.Enabled = true
		workspace.Maps.City.Story.Enabled = false
		workspace.Maps.Base.Story.Enabled = false
		chosenMap.Value = "Prison"
	end
	if workspace.Maps.Base.Votes.Value == workspace.Maps.City.Votes.Value and workspace.Maps.Prison.Votes.Value then
		local random = math.random(1,3)
		if random == 1 then
			workspace.Maps.Base.Story.Enabled = true
			chosenMap.Value = "Base"
		end
		if random == 2 then
			workspace.Maps.City.Story.Enabled = true
			chosenMap.Value = "City"
		end
		if random == 3 then
			workspace.Maps.Prison.Story.Enabled = true
			chosenMap.Value = "Prison"
		end
	end
	workspace.Game.Value = true
	wait(1)
	workspace.Maps.Base.Votes.Value = 0
	workspace.Maps.City.Votes.Value = 0
	workspace.Maps.Prison.Votes.Value = 0
2 Likes

You dont disable any of the others in the block:

		if random == 1 then
			workspace.Maps.Base.Story.Enabled = true
			chosenMap.Value = "Base"
		end
		if random == 2 then
			workspace.Maps.City.Story.Enabled = true
			chosenMap.Value = "City"
		end
		if random == 3 then
			workspace.Maps.Prison.Story.Enabled = true
			chosenMap.Value = "Prison"
		end

Try making a function to disable 2 options and leave the third enabled as so (to clean up ur code):

local function enable(one, two, three, pick : number)
	if pick == 1 then
		one.Enabled = true
		two.Enabled = false
		three.Enabled = false
	elseif pick == 2 then
		one.Enabled = false
		two.Enabled = true
		three.Enabled = false
	elseif pick == 3 then
		one.Enabled = false
		two.Enabled = false
		three.Enabled = true
	end
end
	



It doesn’t seem to work, it still enables another script randomly. it either does or it doesnt its just random

i’m not sure what’s going on but you should just loop through all of the maps instead of checking each one

local function ResetVotes()
  for _, Map in Maps:GetChildren() do
    Map.Votes.Value = 0
  end
end

local function ResetMapStories()
  for _, Map in Maps:GetChildren() do
    Map.Story.Enabled = false
  end
end

local function GetVotes()
  local Votes = {}
  
  for _, Map in Maps:GetChildren() do
    Votes[Map] = Map.Votes.Value
  end
  
  return Votes
end

local function GetMostVotedMap()
  local MostVoted = nil
  local MapVotes = GetVotes()
  local EqualVotes = {}
  
  for Map, Votes in MapVotes do
    if not MostVoted then MostVoted = Map continue end -- Set MostVoted to the first map in the array
    MostVoted = (MostVoted.Votes.Value < Votes) and Map or MostVoted
  end
  
  for Map, Votes in MapVotes do -- Find maps that have votes equal to the most voted map
    if Votes ~= MostVoted.Votes.Value then continue end
    table.insert(EqualVotes, Map)
  end
  
  if EqualVotes > 1 then -- e.g. If Prison and City has equal votes, pick one of those maps randomly
    MostVoted = EqualVotes[math.random(#EqualVotes)]
  end
  
  return MostVoted
end

-- Now all the 'real' code is down here
ResetMapStories()

local VotedMap = GetMostVotedMap()
VotedMap.Story.Enabled = true
ChosenMap.Value = VotedMap.Name
GameBegan.Value = true
task.delay(1, ResetVotes)

don’t expect this to work if you copied it and pasted it; it’s just an example

How would the error attempt to compare nil < number be fixed?

The problem is here:

	for Map, Votes in MapVotes do
		MostVoted = (MostVoted < Votes) and Map or MostVoted
	end
for Map, Votes in MapVotes do
  if not MostVoted then MostVoted = Map continue end -- Set MostVoted to the first map in the array
  MostVoted = (MostVoted.Votes.Value < Votes) and Map or MostVoted
end