FireAllClient problem/help

I am trying to make it so that when some values are met, a remove event will fire which will, in turn, enable a GUI

This code isn’t working, it prints nothing

First Script Normal Script

local rs = game:GetService("ReplicatedStorage")
local Finished = rs:WaitForChild("FinishedRemote")
local player = game.Players.LocalPlayer
local B = script.Parent.Bodies.Value
local H = script.Parent.Hostages.Value
local W = script.Parent.Weapons.Value

while wait() do
	if B >= 8 and H >= 1 and W >= 1 then
		print("ea")
		Finished:FireAllClients()
	else
		
	end
end

Second Script Local Script

local rs = game:GetService("ReplicatedStorage")
local Finished = rs:WaitForChild("FinishedRemote")

Finished.OnClientEvent:Connect(function()
	print("eg1a")
	script.Parent.Enabled = true
end)

You cant get the player like that in server scripts.

I never used the player variable in the actual script tho

– comment to make it go up to the top of the thread

Why is this line here in a Serverscript? You should remove it, it might be causing the problem by erroing and stopping the script.

Could you open the console and send any errors in in?

Sorry, my bad.

LocalPlayer does not error but returns empty in server

1 Like

First of all, with valuebases you should refer to

local xd = ValueBase
xd.Value

Not

local xd = ValueBase.Value

Because if you do the second thing the variable will store the current value only

Try to fire the remote event without the if statement

Second of all, no, localplayer is not the issue since it returns empty in the server, it does not error and you are not using it, but it’s useless

Third of all, I can see that your script and valuebases are probably inside a character, am I right? If that’s true, please stop doing this. StarterCharacterScripts, or relying on character children is not good and is bad practice.

1 Like

I put the fire thing before the while loop and it still did nothing and the values are just inside a folder in workspace

Your script is yielding a waitforchild call probably, can you put a print instead of the fire event?


it printed the 13 but didn’t enable the GUI

In your local script, before the onclientevent, can you put a print?
And does it print the eg1a

it doesn’t print eg1a, I put a print before the onclientevent and it worked

Sorry I meant localscript haha

I think I know your issue, the serverscript loads first than the localscript so when you define the event in the localscript, it does not receive it because it was fired before, can you test this in the server script?

while task.wait(3) do
   remote:FireAllClients()
end

Here is your final fixed serverscript:

local rs = game:GetService("ReplicatedStorage")
local FinishedRemote = rs:WaitForChild("FinishedRemote")
local B = script.Parent.Bodies
local H = script.Parent.Hostages
local W = script.Parent.Weapons

while task.wait() do
	if B.Value >= 8 and H.Value >= 1 and W.Value >= 1 then
		Finished:FireAllClients()	
	end
end
1 Like