I’m trying to make a map voting system where whatever map has the most votes gets selected. However, it always selects Happy Home of Robloxia no matter the outcome of the vote.
Here is my script:
local a1 = game.Workspace.Board1.Votes.Value
local b1 = game.Workspace.Board2.Votes.Value
local c1 = game.ReplicatedStorage.Maps[“Happy Home of Robloxia”]
local d1 = game.ReplicatedStorage.Maps[“The Big Tree”]
local a = 1
if a == 1 then
wait(30)
if a1 >= b1 then
local Clone = c1:Clone()
Clone.Parent = game.Workspace
end
if b1 > a1 then
local Clone = d1:Clone()
Clone.Parent = game.Workspace
end
game.Workspace.Part1.Script.Disabled = false
a = 2
wait(1)
game.Workspace.Part1.Script.Disabled = true
end
if a1 >= b1 then
local Clone = c1:Clone()
Clone.Parent = game.Workspace
elseif b1 > a1 then --Add an elseif instead of adding 2 ifs
local Clone = d1:Clone()
Clone.Parent = game.Workspace
end```
The teleporter just teleports to a part where the maps would spawn, so that’s not the issue, but I can send the script anyway.
local Teleport = “MapPart”
function Touch(hit)
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
local Pos = script.Parent.Parent:findFirstChild(Teleport)
hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end
--[[ Table ]]--
local Maps = {
["Map1"] = 0, -- Add all the maps in here
["Map2"] = 0,
["Map3"] = 0,
-- So on for the amount of maps you have
}
--[[ Variables ]]--
local HighestVotes = -1 -- To see who has the most votes // Do -1 so that if a map has 0 it wont break the system
local Part1 = -- Make this the part they touch, for the vote to count
local Part2 = -- Cary on for the amount of buttons, and maps
--[[ Events ]]--
Part1.Touched:Connect(function()
Map1 = Map1 + 1 -- Adding 1 vote to the map everytime it is touched, really basic but players can spam it so add
-- something that would make it so if the player has already voted don't count there vote
end)
-- So on for all parts
--[[ Function ]]--
local function GetVotedMap()
for _, map in pairs(Maps) do
if map > HighestVotes then
HighestVotes = map
end
end
return HighestVotes
end
print(GetVotedMap) -- Print Number of votes for highest map
-- Once you have don't this then simpily find the map with the most votes
-- and teleport them to it
-- This is by no means the best way, but to get started with it do something similar to this