Hello, I am making a map voting system for practice, and I do not know how to detect if Map1Votes is greater than Map2Votes or if Map2Votes is greater than Map3Votes.
If you don’t know what I am talking about, here is the code I wrote;
local work = game:GetService("Workspace")
local MapsFolder = work.MapVoting
while task.wait(0.1) do
if MapsFolder.Voting.Value == true then
task.wait(10) -- Wait how long the voting lasts
local Map1 = MapsFolder.Map1
local Map2 = MapsFolder.Map2
local Map3 = MapsFolder.Map3
local Map1Value = Map1.Votes.Value
local Map2Value = Map1.Votes.Value
local Map3Value = Map1.Votes.Value
-- here I want to detect which is the highest value.
end
end
Using if statements and checking if the votes are higher than the most votes.
local work = game:GetService("Workspace")
local MapsFolder = work.MapVoting
local MostVotes = 0
local CurrentMap = "Map1"
while task.wait(0.1) do
if MapsFolder.Voting.Value == true then
task.wait(10) -- Wait how long the voting lasts
MostVotes = 0
CurrentMap = ""
local Map1 = MapsFolder.Map1
local Map2 = MapsFolder.Map2
local Map3 = MapsFolder.Map3
local Map1Value = Map1.Votes.Value
local Map2Value = Map1.Votes.Value
local Map3Value = Map1.Votes.Value
if Map1Value > MostVotes then
CurrentMap = "Map1"
MostVotes = Map1Value
else
if Map2Value > MostVotes then
CurrentMap = "Map2"
MostVotes = Map2Value
else
if Map3Value > MostVotes then
CurrentMap = "Map3"
MostVotes = Map3Value
end
end
end
end
end
In the code above I used Map1, Map2, and Map3 as strings, but you can set the maps as the actual CurrentMap Value.
local work = game:GetService("Workspace")
local MapsFolder = work.MapVoting
while task.wait(0.1) do
if MapsFolder.Voting.Value == true then
task.wait(10) -- Wait how long the voting lasts
local mapvotes = {}
for _,v in pairs(MapsFolder:GetChildren()) do
mapvotes[#mapvotes + 1] = {Map = v.Name; Value = v.Votes.Value}
end
table.sort(mapvotes, function(a, b)
return a.Value > b.Value
end)
print(mapvotes[1]) -- prints the highest-voted map
end
local work = game:GetService("Workspace")
local MapsFolder = work.MapVoting
while task.wait(0.1) do
if MapsFolder.Voting.Value == true then
task.wait(10) -- Wait how long the voting lasts
local Map1 = MapsFolder.Map1
local Map2 = MapsFolder.Map2
local Map3 = MapsFolder.Map3
local Map1Value = Map1.Votes.Value
local Map2Value = Map1.Votes.Value
local Map3Value = Map1.Votes.Value
print(math.max(Map1Value, Map2Value, Map3Value))
end
end```