I am making a game round system, when I FireAllClients from the server, it works, but in the onClientEvent part I fire the server which doesn’t work.
ServerScript
local roundTime = 180
local intermissionTime = 10
local inRound = false
local intermissionDone = false
local mapVoting = false
local roundStarting = false
local RS = game:GetService("ReplicatedStorage")
local mapVotingParts = game.Workspace.Lobby.MapVotingArea.MapVoting
local Teams = {game:GetService("Teams"):GetChildren()}
local SplitTeams = function()
local Players = game.Players:GetPlayers()
for i = 1, #Players do
Players[i].Team = Teams[i%#Teams]
end
end
while wait() do
local players = game.Players:GetChildren()
if #players >= 2 then
if inRound == false then
if intermissionDone == false then
for i = intermissionTime, 1, -1 do
wait(1)
intermissionTime = intermissionTime - 1
RS.Events.IntermissionTimeEvent:FireAllClients(intermissionTime)
if intermissionTime == 0 then
intermissionDone = true
end
end
else
-- important part -----------------------------------------------------
if mapVoting == false then
mapVoting = true
RS.Events.MapVotingStartEvent:FireAllClients()
mapVotingParts.VoteMap1.SurfaceGui.MapName.Text = "CASTLE"
mapVotingParts.VoteMap2.SurfaceGui.MapName.Text = "PYRAMID"
mapVotingParts.VoteMap1.SurfaceGui.VotesGui.Text = "VOTES: ".. 0
mapVotingParts.VoteMap2.SurfaceGui.VotesGui.Text = "VOTES: ".. 0
---------------------------------------------------------------
mapVotingParts.VoteMapPad1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if mapVoting == true then
RS.Events.MapVotingEvent1:FireClient(player)
end
end
end)
mapVotingParts.VoteMapPad2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if mapVoting == true then
RS.Events.MapVotingEvent2:FireClient(player)
end
end
end)
RS.Events.MapVotingEvent1.OnServerEvent:Connect(function(player)
mapVotingParts.VoteMap1.Votes.Value = mapVotingParts.VoteMap1.Votes.Value + 1
mapVotingParts.VoteMap1.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap1.Votes.Value
end)
RS.Events.MapVotingEvent2.OnServerEvent:Connect(function(player)
mapVotingParts.VoteMap2.Votes.Value = mapVotingParts.VoteMap2.Votes.Value + 1
mapVotingParts.VoteMap2.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap2.Votes.Value
end)
RS.Events.ReMapVotingEvent1.OnServerEvent:Connect(function(player)
mapVotingParts.VoteMap1.Votes.Value = mapVotingParts.VoteMap1.Votes.Value + 1
mapVotingParts.VoteMap1.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap1.Votes.Value
mapVotingParts.VoteMap2.Votes.Value = mapVotingParts.VoteMap2.Votes.Value - 1
mapVotingParts.VoteMap2.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap2.Votes.Value
end)
RS.Events.ReMapVotingEvent2.OnServerEvent:Connect(function(player)
mapVotingParts.VoteMap2.Votes.Value = mapVotingParts.VoteMap2.Votes.Value + 1
mapVotingParts.VoteMap2.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap2.Votes.Value
mapVotingParts.VoteMap1.Votes.Value = mapVotingParts.VoteMap1.Votes.Value - 1
mapVotingParts.VoteMap1.SurfaceGui.VotesGui.Text = "VOTES: ".. mapVotingParts.VoteMap1.Votes.Value
end)
end
end
else
end
else
RS.Events.NotEnoughPlayersEvent:FireAllClients()
end
end
-- important part --------------------------------------------------------------------------------
RS.Events.RoundStartingEvent.OnServerEvent:Connect(function()
local votes = mapVotingParts.VoteMap1.Votes
local votes2 = mapVotingParts.VoteMap2.Votes
if votes.Value > votes2.Value then
mapVotingParts.ChosenMap.Value = votes.Parent.SurfaceGui.MapName.Text
elseif votes2.Value > votes.Value then
mapVotingParts.ChosenMap.Value = votes2.Parent.SurfaceGui.MapName.Text
elseif votes.Value == votes2.Value then
local randomMap = math.random(1,2)
if randomMap == 1 then
mapVotingParts.ChosenMap.Value = votes.Parent.SurfaceGui.MapName.Text
else
mapVotingParts.ChosenMap.Value = votes2.Parent.SurfaceGui.MapName.Text
end
end
mapVoting = false
inRound = true
wait(0.1)
if mapVotingParts.ChosenMap.Value == "CASTLE" then
RS.Maps.CastleMap:Clone().Parent = workspace
local greenTeam = Instance.new("Team")
greenTeam.TeamColor = BrickColor.new("Lime green")
greenTeam.Name = "Green Team"
greenTeam.Parent = game:GetService("Teams")
local tealTeam = Instance.new("Team")
tealTeam.TeamColor = BrickColor.new("Toothpaste")
tealTeam.Name = "Teal Team"
tealTeam.Parent = game:GetService("Teams")
RS.Events.KillAllPlayersEvent:FireAllClients()
RS.Events.KillAllPlayersEvent.OnServerEvent:Connect(function(player, char)
char.Humanoid.Health = 0
end)
else
RS.Maps.DesertMap:Clone().Parent = workspace
end
votes.Value = 0
votes2.Value = 0
votes.Parent.SurfaceGui.MapName.Text = ""
votes.Parent.SurfaceGui.VotesGui.Text = ""
votes2.Parent.SurfaceGui.MapName.Text = ""
votes2.Parent.SurfaceGui.VotesGui.Text = ""
end)
-------------------------------------------------------------------------------------
local script
RS.Events.MapVotingStartEvent.OnClientEvent:Connect(function()
script.Parent.Text = "MAP VOTING"
wait(10)
script.Parent.Text = "STARTING"
RS.Events.RoundStartingEvent:FireServer()
mapVotingParts.VoteMapPad1.BrickColor = BrickColor.new("Medium stone grey")
mapVotingParts.VoteMapPad2.BrickColor = BrickColor.new("Medium stone grey")
end)