I’m trying to make a map voting system similar to horrific housing, where the ui pops up when the round starts, aka when their is 2 players in game. Please Help.
Script:
local voteStates = game.ServerStorage.States.MapVote
local playersVoted1 = {}
local playersVoted2 = {}
local playersVoted3 = {}
function refreshCounts()
-- Set new values
voteStates.Count1.Value = table.getn(playersVoted1)
voteStates.Count2.Value = table.getn(playersVoted2)
voteStates.Count3.Value = table.getn(playersVoted3)
end
function clearTables()
-- Clear tables
playersVoted1 = {}
playersVoted2 = {}
playersVoted3 = {}
end
game.ServerStorage.States.MapVote.Map1.Changed:connect(clearTables)
game.ServerStorage.States.MapVote.Map2.Changed:connect(clearTables)
game.ServerStorage.States.MapVote.Map3.Changed:connect(clearTables)
script.Parent.Vote1.MouseButton1Click:connect(function(Click)
-- Check if player
if Click.Parent:FindFirstChild("Humanoid") then
-- Get actual Player object
local plr = game.Players:GetPlayerFromCharacter(Click.Parent)
-- Check if already voted
for _, i in pairs(playersVoted1) do
if i == plr then
return
end
end
-- Insert into vote table
table.insert(playersVoted1, plr)
-- Remove from other tables if in
for n, i in pairs(playersVoted2) do
if i == plr then
table.remove(playersVoted2, n)
break
end
end
for n, i in pairs(playersVoted3) do
if i == plr then
table.remove(playersVoted3, n)
break
end
end
end
-- Refresh counts
refreshCounts()
end)
script.Parent.Vote2.Touched:connect(function(Click)
-- Check if player
if Click.Parent:FindFirstChild("Humanoid") then
-- Get actual Player object
local plr = game.Players:GetPlayerFromCharacter(Click.Parent)
-- Check if already voted
for _, i in pairs(playersVoted2) do
if i == plr then
return
end
end
-- Insert into vote table
table.insert(playersVoted2, plr)
-- Remove from other tables if in
for n, i in pairs(playersVoted1) do
if i == plr then
table.remove(playersVoted1, n)
break
end
end
for n, i in pairs(playersVoted3) do
if i == plr then
table.remove(playersVoted3, n)
break
end
end
end
-- Refresh counts
refreshCounts()
end)
script.Parent.Vote3.Touched:connect(function(Click)
-- Check if player
if Click.Parent:FindFirstChild("Humanoid") then
-- Get actual Player object
local plr = game.Players:GetPlayerFromCharacter(Click.Parent)
-- Check if already voted
for _, i in pairs(playersVoted3) do
if i == plr then
return
end
end
-- Insert into vote table
table.insert(playersVoted3, plr)
-- Remove from other tables if in
for n, i in pairs(playersVoted1) do
if i == plr then
table.remove(playersVoted1, n)
break
end
end
for n, i in pairs(playersVoted2) do
if i == plr then
table.remove(playersVoted2, n)
break
end
end
end
-- Refresh counts
refreshCounts()
end)