Event fired based on the count of players?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to learn how to avoid and fix this.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is, if i use “FireAllClients” it fires it once then after a few seconds another time and in a loop until it reaches the end. Example: if theres 3 players, then it will fire once wait and fire another time, wait and fire. If i use “FireClient” it will only fire for one player…
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking on the devforum, scriptinghelpers, youtube, nothing worked.

MainHandler (server script):

llocal roundLength = 200
local intermissionLength = 25
local status = game.ReplicatedStorage.IntermissionStatus
local inround = game.ReplicatedStorage.InRound

local roundStart = game.ReplicatedStorage.remoteEvents.round.roundStart
local roundEnd = game.ReplicatedStorage.remoteEvents.round.roundEnd

local hideML = game.ReplicatedStorage.remoteEvents.mapLoading.hideMapLoading
local showML = game.ReplicatedStorage.remoteEvents.mapLoading.showMapLoading

local knife = game.ReplicatedStorage.Knife:Clone()
local gun = game.ReplicatedStorage.groverGun:Clone()

local mineshaftR = game.ReplicatedStorage.remoteEvents.maps.mineshaft
local milbaseR = game.ReplicatedStorage.remoteEvents.maps.milbase
local ravenRockR = game.ReplicatedStorage.remoteEvents.maps.ravenRock
local lobby = game.ReplicatedStorage.remoteEvents.maps.lobby
local spR = game.ReplicatedStorage.remoteEvents.maps.spMC

local showRole = game.ReplicatedStorage.remoteEvents.displayRole:WaitForChild("displayR")
local hideRole = game.ReplicatedStorage.remoteEvents.displayRole:WaitForChild("hideR")

local loadingMap = game.StarterGui:WaitForChild("loadingMap")

local hide = game.ReplicatedStorage.remoteEvents.mapLoading:WaitForChild("hideGuis")
local show = game.ReplicatedStorage.remoteEvents.mapLoading:WaitForChild("showGuis")


local function roundTimer()
	
	while wait() do
		for i = intermissionLength, 1, -1 do
			inround.Value = false
			wait(1)
			status.Value = "Intermission: ".. i .." seconds left!"
			wait(1)
			roundEnd:FireAllClients()
		end
		for i = roundLength, 1, -1 do
			inround.Value = true
			wait(1)
			status.Value = "Game: ".. i .." seconds left!"
			wait(1)
			roundStart:FireAllClients()
		end
		
	end
	
end


randomMapNumber = math.random(1,4)
inround.Changed:Connect(function()
	if inround.Value == true then	
		for _, player in pairs(game.Players:GetChildren()) do
			--local randomNumber = math.random(1,3)
			local char = player.Character
			
			wait(1)
			if randomMapNumber == 1 then
				wait(2)
				showML:FireAllClients()
				hide:FireAllClients()
				wait(17)
				mineshaftR:FireAllClients()
				hideML:FireAllClients()
				show:FireAllClients()
				showRole:FireAllClients()
				wait(10)
				hideRole:FireAllClients()
			elseif randomMapNumber == 2 then
				wait(2)
				showML:FireAllClients()
				hide:FireAllClients()
				wait(17)
				milbaseR:FireAllClients()
				hideML:FireAllClients()
				show:FireAllClients()
				showRole:FireAllClients()
				wait(10)
				hideRole:FireAllClients()
			elseif randomMapNumber == 3 then
				wait(2)
				loadingMap.Enabled = true
				showML:FireAllClients()
				hide:FireAllClients()
				wait(17)
				ravenRockR:FireAllClients()
				hideML:FireAllClients()
				show:FireAllClients()
				showRole:FireAllClients()
				wait(10)
				hideRole:FireAllClients()
			elseif randomMapNumber == 4 then
				wait(2)
				showML:FireAllClients()
				hide:FireAllClients()
				wait(17)
				spR:FireAllClients()
				hideML:FireAllClients()
				show:FireAllClients()
				showRole:FireAllClients()
				wait(10)
				hideRole:FireAllClients()
			end
			
			player.TeamColor = BrickColor.new("Institutional white")		
		end
	else
		randomMapNumber = math.random(1,4)
		for _,player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			wait(1)
			hide:FireAllClient(player)
			wait(17)
			hideML:FireAllClient(player)
			show:FireClient(player)
			lobby:FireAllClients()
			player.TeamColor = BrickColor.new("Medium stone grey")
		end
	end
	
end)


spawn(roundTimer)                                                                                                                                                                                                        
1 Like

I’m not too sure, about what you’re trying to achieve, but I’m guessing, since you’re looping through the players, you actually only want these events to fire the specefic player, and not every player?

Try using :FireClient(player) instead, if that’s the case.

Else, I don’t really get what you’re trying to do here. Let me know if it helped :slight_smile:

No thats not the case, im trying to fire it for every player but just once, but if theres 12 players, it fires and it waits in a loop 12 times.

Just remove the player loop, or break it after the 1st one?

3 Likes