Hello. I have some code here whose function is to wait 15 seconds for the intermission, then wait 10 seconds for map voting. At the start of these 10 seconds, 3 maps are randomly chosen to be displayed on the display pads. Players will vote on which map they want by stepping on the part that correlates with the map of their choice (kind of like in Murder Mystery 2). After map voting, the maps on the display pads and their votes disappear and the game goes on by telling everyone which map was the winner. Then it plays the round for 10 seconds and it loops, etc.
Everything works up until picking a winner. It seems as if the first time around, it works perfectly, but it seems to become inconsistent in the next rounds as it randomly picks a map on the display pads to win, rather than picking the map with the most votes. If you can find an error with my code, please let me know.
Thank you.
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 0 --minutes
local seconds = 11 --seconds
local status = game.Players.LocalPlayer.PlayerGui.Status:WaitForChild("Status")
local VotingSystem = game.Workspace:WaitForChild("VotingSystem")
local Pad1 = VotingSystem:WaitForChild("Pad1")
local Pad2 = VotingSystem:WaitForChild("Pad2")
local Pad3 = VotingSystem:WaitForChild("Pad3")
local title1 = VotingSystem.VotingDisplay.SurfaceGui.Pad1:WaitForChild("Header")
local title2 = VotingSystem.VotingDisplay.SurfaceGui.Pad2:WaitForChild("Header")
local title3 = VotingSystem.VotingDisplay.SurfaceGui.Pad3:WaitForChild("Header")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local doneVoting = ReplicatedStorage:WaitForChild("doneVoting")
title1.Text = ""
title2.Text = ""
title3.Text = ""
while true do
status.Text = "Intermission"
secondsvalue.Value = 15
repeat
secondsvalue.Value = secondsvalue.Value - 1
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
status.Text = "Voting In Progress"
secondsvalue.Value = 10
game.Players.PlayerAdded:Connect(function(player)
local Vote = Instance.new("StringValue")
Vote.Name = "Vote"
Vote.Parent = player
Vote.Value = "NA"
end)
-- Vote Counter
local function UpdateDisplay()
VotingSystem.VotingDisplay.SurfaceGui.Pad1.Counter.Text = Pad1.Votes.Value
VotingSystem.VotingDisplay.SurfaceGui.Pad2.Counter.Text = Pad2.Votes.Value
VotingSystem.VotingDisplay.SurfaceGui.Pad3.Counter.Text = Pad3.Votes.Value
end
for i, Pad in pairs (game.Workspace.VotingSystem:GetChildren())do
if Pad.Name ~= "VotingDisplay" then
Pad.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Vote.Value ~= Pad then
Pad.Votes.Value = Pad.Votes.Value + 1
if player.Vote.Value ~= "NA" then
local padToSubtract = VotingSystem:FindFirstChild(player.Vote.Value)
padToSubtract.Votes.Value = padToSubtract.Votes.Value - 1
end
player.Vote.Value = Pad.Name
UpdateDisplay()
end
end
end)
end
end
-- Picking which maps to vote between
local Maps = game.Lighting.Maps:GetChildren()
local voteMap1 = Maps[math.random(1, #Maps)]
local voteMap2 = Maps[math.random(1, #Maps)]
local voteMap3 = Maps[math.random(1, #Maps)]
if voteMap2 == voteMap1 then
repeat
voteMap2 = Maps[math.random(1, #Maps)]
until voteMap2 ~= voteMap1
end
if voteMap3 == voteMap2 or voteMap3 == voteMap1 then
repeat
voteMap3 = Maps[math.random(1, #Maps)]
until voteMap3 ~= voteMap2 and voteMap3 ~= voteMap1
end
title1.Text = tostring(voteMap1)
title2.Text = tostring(voteMap2)
title3.Text = tostring(voteMap3)
-- The calculating winner function
local function CalculateWinner()
local padVotes = {
[tostring(voteMap1)] = Pad1.Votes.Value,
[tostring(voteMap2)] = Pad2.Votes.Value,
[tostring(voteMap3)] = Pad3.Votes.Value,
}
local highest = 0
local pad = nil
for i, v in pairs (padVotes) do
if v > highest then
highest = v
pad = i
end
end
return pad
end
-- Waiting for voting timer to run out
repeat
secondsvalue.Value = secondsvalue.Value - 1
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
-- (Calculating winner before votes reset.)
CalculateWinner()
-- Resetting data
spawn(function()
while wait(1) do
if secondsvalue.Value <= 0 then
doneVoting.Value = true
CalculateWinner()
Pad1.Votes.Value = 0
Pad2.Votes.Value = 0
Pad3.Votes.Value = 0
VotingSystem.VotingDisplay.SurfaceGui.Pad1.Counter.Text = 0
VotingSystem.VotingDisplay.SurfaceGui.Pad2.Counter.Text = 0
VotingSystem.VotingDisplay.SurfaceGui.Pad3.Counter.Text = 0
title1.Text = ""
title2.Text = ""
title3.Text = ""
wait(5)
doneVoting.Value = false
end
end
end)
-- Stating the winning map
local mapWinner = CalculateWinner()
if mapWinner == nil then
local padVotes = {tostring(voteMap1),tostring(voteMap2),tostring(voteMap3)}
mapWinner = padVotes[math.random(1,#padVotes)]
end
status.Text = "Loading Map ".. mapWinner
wait(5)
status.Text = "Round In Progress"
minutesvalue.Value = minutes
secondsvalue.Value = seconds
repeat
if secondsvalue.Value <= 0 then
minutesvalue.Value = minutesvalue.Value - 1
secondsvalue.Value = 59
else
secondsvalue.Value = secondsvalue.Value - 1
end
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
status.Text = "Game Over!"
wait(5)
end

2 comments
I'm not sure if this was done in the script or not, but maybe you need to clear out the string values value.
So I believe I cleared out all my string values including the new ones: voteMap1, voteMap2, voteMap3, and mapWinner. These are cleared out along with the ones already in the code. However, the problem still is occurring.