Hello Developers!
I want to know on how to make a Random Voting System if players don’t vote on any maps or if the map votes are a tie.
Thanks for reading!
Hello Developers!
I want to know on how to make a Random Voting System if players don’t vote on any maps or if the map votes are a tie.
Thanks for reading!
If you already have a script for voting, put this after the voting timeout:
local MapsNames = {}
Vote = MapsNames[math.random(MapsNames)]
Here is a small example:
local Maps = {}
function VoteRandom(Player)
wait() --Time
local Vote = Maps[math.random(#Maps)]
print(Player.Name, ":", Vote)
end
Do you mean you already have the vote set up but you want to know how to decide the vote? If so then you can loop through the votes and check if it is greater than the previous option.
--example
local Votes = {
["Lava Fields"] = 5
["Desert"] = 7
["Snow"] = 3
}
local highestVotes = -1
local chosenmap
for i, v in pairs(Votes) do
if v > highestVotes then
highestVotes = v
chosenmap = i
end
end
I don’t have the script for voting.
You can use GUIs or Parts as touchpads. When a player touches the pad or clicks the button you make it so that the Number of votes of a particular map increase. (The IntValue increases by 1). At the end of the voting. You could calculate the maximum voted map using conditional statements and select the map accordingly.
But what if the votes are a tie
You could choose a random map between the maps by using Math.random()
How do I use math.random way???
You could take the maps. You could store the equally voted maps in a folder named EqualVotes in the workspace.
And accordingly do this -
local RandomMap = math.random(1, #workspace.EqualVotes:GetChildren()) --gets a value between 0 and number of equally voted map.
local SelectedMap = workspace.EqualVotes[RandomMap]
But TheDevKing didn’t show how to do a random map vote.