Hey, I’m having issues with my round system, I have 2 scripts client-sided and server-sided. However, when the game starts, with 2 players if one 1 votes for a map, and the other not, the intermission will start and they will both be teleported which is good but when the round ends and they’re back to voting and the OTHER player votes for a map, it starts the round immediately without the intermission. (The intermission starts after the vote has been cast, otherwise, it will wait until a map gets a vote then it will start.)
main handler - server script
-- Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
-- Data Store
local banData = DataStoreService:GetDataStore("banData")
-- Variables
local commsFolder = game.ReplicatedStorage.comms
local remotes = commsFolder.remotes
local adminPanel = game.ServerStorage.AdminPanel
local groupRestriction = 16183882
local intermissionTime = 10
local roundTime = 10
local spawnPart = game.Workspace:WaitForChild("spawn")
-- Remotes
local banRemote = remotes.ban
local notifyRemote = remotes.notify
local roundEndRemote = remotes.roundEnd
local intermissionEndRemote = remotes.intermissionEnd
-- Booleans
local activeRound = commsFolder.activeRound
local intermission = commsFolder.intermission
-- Global Variables
local alreadyCounting = false
local intermissionEndRemoteConnection
-- Functions
local function SetBanData(plr)
local plr_key = plr.Name.."banDataValue"
banData:SetAsync(plr_key, false)
local success, res = pcall(function()
return banData:GetAsync(plr_key)
end)
if success then
if res then
plr:Kick("You are banned from this game!")
else
banData:GetAsync(plr_key, false)
end
end
end
local function MakeAdmin(plr)
if plr:GetRankInGroup(groupRestriction) >= 1 then
local AdminValue = Instance.new("BoolValue", plr)
AdminValue.Name = "isAdmin"
AdminValue.Value = true
local panelClone = adminPanel:Clone()
panelClone.Parent = plr.PlayerGui:WaitForChild("ScreenGui")
end
end
local function GameRoles()
local players = Players:GetPlayers()
local numPlayers = #players
local watcherIndex = math.random(1, numPlayers)
for i, player in ipairs(players) do
local role = (i == watcherIndex) and "Watcher" or "Civilian"
local watcherUI = commsFolder.watcherText:Clone()
print(player.Name .. " - Role: " .. role)
if role == "Watcher" then
watcherUI.Parent = player.PlayerGui.ScreenGui
else
watcherUI.Text = "You're a civilian!"
watcherUI.Parent = player.PlayerGui.ScreenGui
end
end
end
local function CheckVotes()
local startRemote = remotes.roundStart
local mapsFolder = commsFolder.mapVotes
local maxVotes = 0
local chosenMap
for _, map in pairs(mapsFolder:GetChildren()) do
if map:IsA("NumberValue") then
local mapVotes = map.Value
if mapVotes > maxVotes then
maxVotes = mapVotes
chosenMap = map.Name
end
end
end
if chosenMap and maxVotes > 0 then
startRemote:FireAllClients(chosenMap)
GameRoles()
maxVotes = 0
chosenMap = nil
for _, map in pairs(mapsFolder:GetChildren()) do
map.Value = 0
end
else
startRemote:FireAllClients("default")
end
end
local function FirstRound(plr)
local UI = plr.PlayerGui:WaitForChild("ScreenGui")
UI.mapFrame.Visible = false
if activeRound.Value then
print("There is an active round.")
plr.Character:PivotTo(spawnPart.CFrame)
intermission.Value = false
elseif intermission.Value then
plr.Character:PivotTo(spawnPart.CFrame)
UI.mapFrame.Visible = true
if not activeRound.Value then
local intermissionRemote = remotes.intermission
intermissionRemote:FireAllClients(plr)
end
intermissionEndRemote.OnServerEvent:Wait()
intermission.Value = false
activeRound.Value = true
CheckVotes()
end
end
-- Player Added Event
Players.PlayerAdded:Connect(function(plr)
print("Player joined:", plr.Name)
SetBanData(plr)
MakeAdmin(plr)
FirstRound(plr)
end)
-- Round End Event
roundEndRemote.OnServerEvent:Connect(function(plr)
activeRound.Value = false
intermission.Value = true
print("Event triggered")
FirstRound(plr)
end)
-- Ban Remote Event
banRemote.OnServerEvent:Connect(function(player, target, username)
if target:GetRankInGroup(groupRestriction) >= 1 or target.Name == username.Name or not username:FindFirstChild("isAdmin") then
notifyRemote:FireClient(player, false, false, true)
else
if target then
target:Kick("You're banned from this game, by: "..tostring(username.Name))
banData:SetAsync(target.Name.."banDataValue", true)
notifyRemote:FireClient(player, false, true)
for _, player in pairs(Players:GetChildren()) do
local screenGui = player.PlayerGui:FindFirstChild("ScreenGui")
local banlistFrame = screenGui.AdminPanel.Banlist.ScrollingFrame
local banTemplate = banlistFrame.banTemplate
if screenGui:FindFirstChild("AdminPanel") then
local clone = banTemplate:Clone()
clone.Visible = true
clone.Parent = banlistFrame
clone.Text = "Player: "..tostring(player.Name).." | Admin: "..tostring(username.Name)
end
end
end
end
end)
Some of the functions aren’t related to the round system so just check firstround function VoteCheck, etc
Client-sided script, this is mainly the one who replies to events.
local folder = game.ReplicatedStorage.comms
local remotes = folder.remotes
local notifyRemote = remotes.notify
local roundStart = remotes.roundStart
local roundEnd = remotes.roundEnd
local plr = game.Players.LocalPlayer
local intermissionRemote = remotes.intermission
local function hasVotes()
for _, map in pairs(folder.mapVotes:GetChildren()) do
if map.Value > 0 then
return true
end
end
return false
end
intermissionRemote.OnClientEvent:Connect(function()
for countdown = 10, 0, -1 do
repeat
wait(1)
if hasVotes() then
plr.PlayerGui.ScreenGui.timerFrame.TextLabel.Text = "The round will start in.. " .. tostring(countdown)
else
print("No votes have been casted.")
end
until hasVotes()
end
local UI = plr.PlayerGui.ScreenGui
UI.mapFrame.Visible = false
remotes.intermissionEnd:FireServer()
end)
notifyRemote.OnClientEvent:Connect(function(voteFail, playerBan, banFail, makeAdmin)
local messageText = ""
local titleText = ""
if voteFail then
titleText = "Fail!"
messageText = "You have already voted, please be patient while the game starts."
elseif playerBan then
titleText = "Sucess!"
messageText = "The player has been banned from the game, please check the banlist."
elseif banFail then
titleText = "Fail!"
messageText = "You may not ban this user."
elseif makeAdmin then
titleText = "Sucess!"
messageText = "The user is now temp admin of the game!"
end
game:GetService("StarterGui"):SetCore("SendNotification", {
Title = titleText,
Text = messageText,
Icon = "rbxassetid://1234567890", -- Optional
TextSize = 14
})
end)
local roundTime = 10
roundStart.OnClientEvent:Connect(function(map)
local chosenMap = game.Workspace.mapParts:FindFirstChild(map)
if chosenMap then
plr.Character:PivotTo(chosenMap.CFrame)
local UI = plr.PlayerGui.ScreenGui
UI.mapFrame.Visible = false
for countdown = 10, 0, -1 do
wait(1)
plr.PlayerGui.ScreenGui.timerFrame.TextLabel.Text = "The round will end in.."..tostring(countdown)
end
roundEnd:FireServer()
end
end)