Voting System UI

Hello, i want to make a system that does the following:
Lets players click a button UI to add there vote.
Finds which one got the most votes, enters the map in the workspace.
Deals with tied voting.

The first two i could not figure out how to do, but the 3rd maybe i can.

Any help to my problem would help here.

1 Like

You could have a textbutton that is local for the user. When they press it, it fires a remote event in replicated storage with the map number/id

Then, in a serverscript:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Whatever it is called
local VotedPlayers = {}
local Votes = {}
local Winner

RemoteEvent.OnServerEvent:Connect(function(plr, ID)
    if not table.find(VotedPlayers, plr) then --Ensure people can only vote once
        table.insert(VotedPlayers, plr)
        if not Votes[ID] then Votes[ID] = 0 end
        Votes[ID] += 1
    end
end)

-- Then a function to determine the winner could be:
function ChooseWinner()
    local HighestVote = -1 --Dodgy sorting system because I'm tired
    local CurrentWinner
    for ID, Votes in pairs(Votes) do
           if HighestVote < Votes then 
                HighestVote = Votes
                CurrentWinner = ID
            end
    end
    Votes = {}
    VotedPlayers = {}
end

This is a very dodgy system that doesn’t account for ties, and there is probably a better way of doing this xD

2 Likes

Why would we need player id’s as the winner…? Im a bit confused here.

Its not the player ID, its the map ID, which you’ll have to decide which is which

oh, sorry i will try this out. Thanks!