How should I go about doing this?

I’m trying to make a map voting system for my game right now, I already have the GUI for the player and what-not, but I’m stumped on what I should do for the scripting part of all of this.

My initial plan was to make three variables that grab various maps (which I’ve already done). but the issue is now I want to make it so that the voting GUI comes up for all players, and whenever they vote for a map it gets returned back to the server so that I can get a total tally count of every map that the players have voted for.

I’m stuck on how I should give all of the players the voting GUI and check whenever they click on one of the map images, so that I can then send it back to the server.

So what should I do next?

while task.wait() do
	if #Players:GetPlayers() >= 1 then
		for i = 1, 4, 1 do
			statusValue.Value = "◀ ".."Preparing Game.".." ▶"
			task.wait(.5)
			
			statusValue.Value = "◀ ".."Preparing Game..".." ▶"
			task.wait(.5)

			statusValue.Value = "◀ ".."Preparing Game...".." ▶"
			task.wait(.5)
		end
		
		local option1 = maps:GetChildren()[math.random(1, #maps:GetChildren())]
		print(option1)
		
		local option2
		repeat
			option2 = maps:GetChildren()[math.random(1, #maps:GetChildren())]
		until option2 ~= option1
		print(option2)
		
		local option3 
		repeat
			option3 = maps:GetChildren()[math.random(1, #maps:GetChildren())]
		until option3 ~= option1 and option3 ~= option2
		print(option3)
		
		
	end
	
end

2 repeats… not gonna lie but is pretty high for a load script

Have you read about RemoteEvents and RemoteFunctions? They are capable of doing exactly what you’re trying to do here. If you haven’t, I advise that you take some free time from the things you’re working on and try to get well acquainted with server-client communication.

On the server, you will need call :FireAllClients() on a RemoteEvent to tell all the players’ clients that they can vote for a map.

On the client, you will be able to listen for such an event using RemoteEvent.OnClientEvent (RBXScriptSignal). You can then detect when a player votes for a map.

Once the player votes on a map, you can call RemoteEvent:FireServer() to communicate to the server that a player has voted for a map. You can pass the map name as an argument.

Do you have any alternatives for trying to make one map not repeat itself that’s not resource-heavy?

remote events as blox smith told or optimize the script.

The repeats are used to make it so that maps don’t repeat themselves, how will remote events help?

make a previous map table which will store and prevent it from appearing again the next time, bet don’t forget to clear it

I know of a great video on this very subject if you want the link.

It looks very hardcoded I recommend you make some auxiliary functions so you don’t hardcoded it all

What do you mean by hardcoded? And what are auxiliary functions?

if you want to keep it simple, you can use global variables, however you will have to take into account that there will be loopholes in the code that hackers can use.

option1.Button1Down:Connect(function()
    _G.option1 += 1
end)
option2.Button1Down:Connect(function()
    _G.option2 += 1
end)
option3.Button1Down:Connect(function()
    _G.option3 += 1
end)

The other option is to use a RemoteEvent and make a checker that each player can only vote once (this is to prevent hackers from voting multiple times when executing the remoteevent)