Voting system doesn't work as expected

I don’t get any errors but the code doesn’t seem to work anyway for some reason, I couldn’t figure out what’s wrong honestly.

function selector:Vote(player: Player, map: string)
	if not player or not map then error("No player or map.") end
	if not self.Queue then error("No queue.") end
	 for i, v in pairs(self.Queue) do
			print("Searching for map..")
			if v.Map == map then
				print("Skipping..")
				continue
			end
			
		   local playerI = table.find(v.Votes, player)
			if playerI then
				print("Player had voted another map before, removing the vote..")
				table.remove(v.Votes, playerI)
			end
	 end
	 
	for i, v in pairs(self.Queue) do
		if v.Map == map and not table.find(v.Votes, player) then
			print(string.format("Assigned %s's vote to %s", player.Name, map))
			table.insert(v.Votes, player)
			break
		end
	end
	print(self.Queue)
end

To confirm, is this is a Module script and how are you handling the arrays/jagged arrays?

Can you show the output when you attempt to use the system?
The code looks like it should work, although there is little contrxt we have, as in where it is called and what arguments are passed in

Yes it’s a module script, here’s the whole thing:

local selector = {}
selector.__index = selector

function selector.Start(maps)
	local self = setmetatable({}, selector)
	self.Maps = maps:GetChildren()
	self.mapsToVote = #self.Maps
	return self
end

function selector:startVoting()
	local availableMaps = {}
	
	local Queue = {
		[1] = {
			Map = nil,
			Votes = {}
		};
		[2] = {
			Map = nil,
			Votes = {}
		};
		[3] = {
			Map = nil,
			Votes = {}
		};
	}
	
	
	repeat
		task.wait()
		for i = 1, self.mapsToVote do
			local map = self.Maps[math.random(1, #self.Maps)]
			--print(map)
			if table.find(availableMaps, map) then
				continue
			end
			table.insert(availableMaps, map)
		end
	until #availableMaps == 3
	
	local modifiedQueue = table.clone(Queue)
	
	print(availableMaps)
	modifiedQueue[1].Map = availableMaps[1]
	modifiedQueue[2].Map = availableMaps[2]
	modifiedQueue[3].Map = availableMaps[3]
	
	self.Queue = modifiedQueue
	print(self.Queue)
end

function selector:Vote(player: Player, map: string)
	if not player or not map then error("No player or map.") end
	if not self.Queue then error("No queue.") end
	 for i, v in pairs(self.Queue) do
			print("Searching for map..")
			if v.Map == map then
				print("Skipping..")
				continue
			end
			
		   local playerI = table.find(v.Votes, player)
			if playerI then
				print("Player had voted another map before, removing the vote..")
				table.remove(v.Votes, playerI)
			end
	 end
	 
	for i, v in pairs(self.Queue) do
		if v.Map == map and not table.find(v.Votes, player) then
			print(string.format("Assigned %s's vote to %s", player.Name, map))
			table.insert(v.Votes, player)
			break
		end
	end
	print(self.Queue)
end


return selector

dunno what I messed up.

I’ma just write you a new one since luckily I also need to make a voting system. Will the maps be in a folder?

I posted the whole thing, you can check (plz)

alright thank you boss appreciate that

Problem is you are storing the Map instance in available maps, and comparing it to the map string. Try doing
if v.Map.Name ==map
Make sure to change it for both if statements

Adding onto what @loltrol2121 said, you could also change “map” to map.Name in this loop too.

Also, what was the point of cloning the queue

I don’t think it clones the queue, but selects 3 random maps to show the player

He coulda done Queue[1].Map = availableMaps[1]

Tables dont clone, they reference each other, so setting the map st index 1 to the map at index one of available maps would modify the original table.

I didnt want to modify the original table so I just cloned it

I meant that the table was using get children, which wouldnt reference the name of the map.
This makes v.Map an instance because it iterates through self.queue

yes I just noticed that but im literally overwhelmed rn I’m trying to update it

Different memory address when you use table.clone so yes it does clone.

Proof:
image

Also, @erdalaga4 the reason i mentioned it was because Queue was a local variable than self.queue so i didnt see a point in doing all of that

Yes thats what I was saying. If you set a table to another table, it doesnt clone the original table, just references it. This is why you use table.clone
This was my fault for not making it clear.

as @loltrol2121 stated v.Map was an instance instead of being a string, so I changed map with map.Name and I think it’s ready-to-go now:

{
[1] = ▼ {
[“Map”] = “Map1”,
[“Votes”] = ▼ {
[1] = player1
}
},
[2] = ▼ {
[“Map”] = “Map2”,
[“Votes”] = {}
},
[3] = ▼ {
[“Map”] = “Map3”,
[“Votes”] = {}
}
}

Thanks for all the help!

small oversight really wasted me an hour..

Almost finished the new version. Just testing it and then I’ll give you the module file

alright, I’ll try gaining more knowledge/experience from your module for myself, thanks for the effort