:FireAllClients() Not working

Hi everyone. I’m writing code to make races and whoever joins the race can win coins. That works alright, but when I try to transfer this information (the winner or if nobody wins) to a localscript to display on a ui, it doesn’t work. I will send small parts of both scripts as the entire script is kinda long and most of it is irrelevant.

ServerScript:

print(hit.Parent.Name.." has won! - SERVER")
					game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire"):FireAllClients(hit.Parent.Name)

-- when someone wins
print("NOBODY WON! - SERVER")
			game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon"):FireAllClients()

-- when nobody wins

LocalScript:

game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire").OnClientEvent:Connect(function(playerwhowon)
	print(playerwhowon.." WON! - CLIENT")
	winnerframe.Visible = true
	winnername.Text = playerwhowon
	coinsamt.Text = "+50 Coins!"
	task.wait(5)
	winnerframe.Visible = false
end)

-- ui when someone wins
game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon").OnClientEvent:Connect(function()
	print("NOBODY WON! - CLIENT")
	winnerframe.Visible = true
	winnername.Text = "Nobody Won!"
	coinsamt.Text = "+0 Coins!"
	task.wait(5)
	winnerframe.Visible = false
end)

-- ui when nobody wins

The UI just doesn’t display, the prints don’t work in the localscript. Any help with this would be appreciated! :slight_smile:

Where is the local script located?

Also can we get the full server script script?

I did some (quick) searching and most of the “FireAllClients not working” is solved because the server fired the event before the client could connect to the event. can you give some context about the firing of the remotes?

Local Script is located somewhere in StarterGui.

local playersPlaying = {}
local parkourroundtime = 20
local finish = game.Workspace.FinishPart
local someonehaswon = false

game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceJoinFire").OnServerEvent:Connect(function(player)
	table.insert(playersPlaying, player)
	print("There are/is currently "..#playersPlaying.." player(s) playing!")
	game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceStartFire").OnServerEvent:Connect(function()
		someonehaswon = false
		
		for i,v in pairs(playersPlaying) do
			v.Character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.ParkourRaceStartPart.CFrame
			if v.Backpack:FindFirstChild("GravityCoil") then
				v.Backpack.GravityCoil:Destroy()
			end
		end
		
		finish.Touched:Connect(function(hit)
			if someonehaswon == false then
				if hit.Parent:FindFirstChild("Humanoid") then
					print("This be a player")
					print(hit.Parent.Name.." has won! - SERVER")
					game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire"):FireAllClients(hit.Parent.Name)
					someonehaswon = true
					
					for i,v in pairs(playersPlaying) do
						v.Character:WaitForChild("Humanoid").Health = 0
					end
					task.wait(0.1)

					for k in pairs(playersPlaying) do
						playersPlaying[k] = nil
					end

				end
			end
		end)	
		
		wait(parkourroundtime)
		
		if someonehaswon == false then
			print("NOBODY WON! - SERVER")
			game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon"):FireAllClients()
			for i,v in pairs(playersPlaying) do
				v.Character:WaitForChild("Humanoid").Health = 0
			end
			
			for k in pairs(playersPlaying) do
				playersPlaying[k] = nil
			end
		end
		
		print("Should be nil:")
		print(playersPlaying)
		print("Round Ended!")
	end)
end)

This is the full localscript and I think it should give you some context on the events:

local winnerframe = script.Parent.Parent.WinnerFrame
local winnername = winnerframe.Winnername
local coinsamt = winnerframe.CoinsText

winnerframe.Visible = false

print(#game.Players:GetPlayers())
local ingame = script.Parent.InGame
ingame.Value = false
local frame = script.Parent
frame.Visible = false

local function promptjoin()
	print("PROMPT TO JOIN SENT")
	frame.Visible = true
	frame.Join.MouseButton1Click:Connect(function()
		frame.Visible = false
		game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceJoinFire"):FireServer(game.Players.LocalPlayer)
	end)
	frame.Nah.MouseButton1Click:Connect(function()
		frame.Visible = false
	end)
	wait(5)
	frame.Visible = false
	game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceStartFire"):FireServer()
end

while true do
	task.wait(25)
	if #game.Players:GetPlayers() == 1 and ingame.Value == false then
		promptjoin()
		print("enough players in game :)! ("..#game.Players:GetPlayers()..")")
	else
		print("NOT ENOUGH PLAYERS OR GAME ALREADY RUNNING!")
	end
end

game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire").OnClientEvent:Connect(function(playerwhowon)
	print(playerwhowon.." WON! - CLIENT")
	winnerframe.Visible = true
	winnername.Text = playerwhowon
	coinsamt.Text = "+50 Coins!"
	task.wait(5)
	winnerframe.Visible = false
end)

game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon").OnClientEvent:Connect(function()
	print("NOBODY WON! - CLIENT")
	winnerframe.Visible = true
	winnername.Text = "Nobody Won!"
	coinsamt.Text = "+0 Coins!"
	task.wait(5)
	winnerframe.Visible = false
end)

this piece of code wont run because it is blocked by the while true do loop, you can change the order to connect to events first before the loop

1 Like

actually, i think you can just do Players.PLayerAdded and check the player count there instead of using a while loop

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.