The issue is that i keep getting this error
Stack Overflow
then the game freezes for abit.
Code
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Maps = ReplicatedStorage:WaitForChild("Maps")
local RunService = game:GetService("RunService")
local GameValues = ReplicatedStorage:WaitForChild("GameValues")
local VotingingInProgress = GameValues:WaitForChild("VotingProgress")
local VotingHandler = {}
VotingHandler.mapVotes = {}
ReplicatedStorage.Remotes.Voting.PlaceVote.OnServerEvent:Connect(function(player,padNumb)
for i,v in VotingHandler.mapVotes do
for x,plr in v.players do
if plr == player.UserId then
table.remove(v.Players,x)
break
end
end
end
for i,v in VotingHandler.mapVotes do
if v.order == padNumb then
table.insert(v.players,player.UserId)
end
end
end)
function getMap()
local randMap = Maps:GetChildren()[math.random(1,#Maps:GetChildren())]
for i,v in VotingHandler.mapVotes do
if v.name == randMap.name then
return getMap()
end
end
return randMap.Name
end
function VotingHandler.MapVoting(dur)
VotingHandler.mapVotes = {}
for i,v in workspace.World.VotingBoard.VotingPads:GetChildren() do
table.insert(VotingHandler.mapVotes, {order = tonumber(v.Name:match("%d+")); name = getMap(); Players = {}})
print(v.Name)
end
GameValues.VotingProgress.Value = true
local start = tick()
while task.wait() do
if tick() - start >= dur then break end
GameValues.Status.Value = "[Voting: " .. math.floor(dur - (tick() - start)) .. "seconds left to vote]"
for i,v in workspace.World.VotingBoard.VotingPads:GetChildren() do
local votes,mapName
for x,map in VotingHandler.mapVotes do
if map.order == tonumber(v.Name:match("%d+")) then
votes = #map.Players
mapName = map.name
break
end
end
GameValues.VotingProgress = false
table.sort(VotingHandler.mapVotes,function(a,b) return #a.Players > #b.Players end)
GameValues.Status.Value = "[ Loading map: " .. VotingHandler.mapVotes[1].name .. "! ]"
task.wait(3)
return Maps:FindFirstChild(VotingHandler.mapVotes[1].name)
end
end
end
return VotingHandler