How would I make a “Challenge” Voting System? Kinda like a game-mode voting system where whichever game mode has the most votes, it will do. (for example Team Deathmatch)
Your question is a little vague, depends on what you already have or your plans.
Make a “round system” that loops, each X amount of seconds it repeats, calling a function at the start, sending remote calls to clients, showing a GUI for all of them with buttons to vote, after X amount seconds make the voting to end, get their votes in server via remotes too, do the math to know which “mode” is the most voted, and form server trigger that mode, and repeat whole process again
Hi,
Here is the process;
- Get the players a voting gui.
- Players send their vote through a RemoteEvent to the server
- The server collects the remote signals, with the voting choice (make sure to do sanity checks on the server like; are they able to vote at this point? is the voting choice even present? is the voting choice even a valid gamemode? ect.)
- After collecting all signals (usually done with a countdown, like they have 10 seconds to vote. Or you could check, if the majority have already voted on a single gamemode, to skip the rest of the remotes)
Loop through all the votes, and check which gamemode vote there is most of.
--Clientside, make sure to detect yourself when the remote should be fired
local VoteRemote = game:GetService("ReplicatedStorage"):WaitForChild("VoteRemote")
local Gamemodes = {Team Deathmatch, Deathmatch, Battle}
local ButtonTemplate = script:WaitForChild("ButtonTemplate")
local VoteFrame = script.Parent:WaitForChild("VoteFrame")
for _, Gamemode in pairs(Gamemodes) do
NewButton = ButtonTemplate:Clone()
local ButtonDebounce = false
NewButton.Activated:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
VoteRemote:FireServer(Gamemode)
task.wait(1)
ButtonDebounce = false
end
end)
NewButton.Parent = VoteFrame
end
--Serverside
local VoteRemote = game.ReplicatedStorage.VoteRemote
local Gamemodes = {Team Deathmatch, Deathmatch, Battle}
local VotedPlayers = {}
local CurrentVotes = {}
local VotingActive = false
VoteRemote.OnServerEvent:Connect(function(Player,VoteChoice)
if not VotingActive then return end -- If voting active
if not VoteChoice then return end -- If VoteChoice is present (not nil)
local ValidVoteChoice = tostring(VoiceChoice) -- Transform vote into string, to check if they sent another type of valuetype, there is also other ways of doing it.
if not ValidVoteChoice then return end -- If not ValidVoteChoice, then it wasn't a number or string
if not table.find(Gamemodes,ValidVoteChoice) then return end -- If we cannot find the string in our valid gamemodes
if VotedPlayers[Player.name] then return end -- If the player have already voted
VotedPlayers[Player.name] = true -- Put them in already voted
table.insert(CurrentVotes,VoteChoice) -- Put their vote into the CurrentVotes table
end)
-- This is your round script, figure out yourself when you want the voting to happen
while task.wait(1)
--Do stuff to check if enough players is present
--
--
-- We've now come to the voting part
VotedPlayers = {} -- reset voted players
CurrentVotes = {} -- reset current votes
VotingActive = true
local AmountOfVotes = 0
local VotingTime = 10
local MostVotedGamemode = Deathmatch (sets deathmatch as default gamemode if no votes for example)
repeat
VotingTime -= 1 -- Goes one second down each loop
-- Make a loop here, that loops through all the votes, and check which gamemode there is voted most on. And set MostVotedGamemode to be that gamemode
task.wait(1) -- this indicates that it's once a second
until AmountOfVotes == AmountOfPlayingPlayers or VotingTime == 0
VotingActive = false
-- Boom, voting done, gamemode found.
print(MostVotedGamemode)
end
Wow, thank you so much for this. But I need help with a lot of things since I’m not the greatest scripter. Idk what to do in “local MostVotedGamemode = Deathmatch” and how I would even make it PLAY that game mode and make it work. If that makes sense. And how would I make it show the number of votes the game mode has?
If this is the case, I would suggest that you try and watch some youtube videos, about round based games. A round based game is exactly that, a game that loops around all the time. This is done in Piggy, Hide n seek games ect.