FireAllClients() not firing

I will try to find a workaround with game.Players:GetChildren() or something.


Where is the local script located within the explorer?

But if anyone can find a solution, I will be very happy.

try putting a print at the top of the local script and see if that prints.

Tested with that too. It prints. The animation event function could be taken as an example too.

If the second print isn’t working, it’s likely that the connection is made after the client is fired.

Try adding a wait(1) before you fire all clients and see if that helps.

This is exactly what is happening. The event is getting fired faster than the player can join. It would be better to fire it specifically for the client once they join.

I am trying my best here; I have changed the script 7 times and none of them works.

I am afraid to use PlayerAdded because that’s storing the variable for the function only, so that won’t work either.

You really shouldn’t be worried about memory that much at the moment.

Though even using PlayerAdded wouldn’t add much memory for the server. Adding a reference to the player instance wouldn’t add memory. The variable would only be pointing to the reference of the player which is already loaded into memory.

1 Like

in the local script right before the connection is made add a print so you can see if the event is fired before the connection is made…

then adjust the wait until the event is fired after…

I am not worrying for memory here (a little bit, map is huge), but the thing I was saying is that if I register the player within the function, it will store only for the function. The rest of the script would consider it nil.

Try creating the connection at the very top of the script and see if it works as a placeholder, this will give us a better idea of where to start.

Client:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
RemoteEvent.OnClientEvent:Connect(function()
    print('received at',os.time())
end)

Server:

wait(5)
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
RemoteEvent:FireAllClients()
print('fired all clients at',os.time())

Or you could just handle camera manipulation on the client without any influence from the server which is probably your best bet.

I have tested that on a baseplate. Works.
On the main game, and only the fired all clients have been received in the output. What is going on…

As I said, the connection is being made after the remote has been fired.

Is the local script you provided the full script?

The first one were just some locals missing. Here is full local script:

--CoreUI elements
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
--Player
local Player = game:GetService("Players").LocalPlayer
--Model
local Model = workspace:FindFirstChild("PlayerCharacter")
local HeadCamera = Model.Head
local SecondCamera = Model.SecondCamera
--ReplicatedStorage stuff
local GameFunctionsModule = game:GetService("ReplicatedStorage"):WaitForChild("GameFunctions")
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
--Camera
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
--Functions
RemoteEvent.OnClientEvent:Connect(function()
print('received at',os.time())
game:GetService("RunService").RenderStepped:Connect(function()
Camera.CFrame = part.CFrame
end)
end)

One of your :WaitForChilds is probably what’s causing it, you’re using an asynchronous function which will pause the thread until it’s found. Try adding the variables inside of the connection and reference them that way.

RemoteEvent.OnClientEvent:Connect(function(part)
    game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
    --Player
    local Player = game:GetService("Players").LocalPlayer
    --Model
    local Model = workspace:FindFirstChild("PlayerCharacter")
    local HeadCamera = Model.Head
    local SecondCamera = Model.SecondCamera
    --ReplicatedStorage stuff
    local GameFunctionsModule = game:GetService("ReplicatedStorage"):WaitForChild("GameFunctions")
    local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
    --Camera
    local Camera = workspace.CurrentCamera
    Camera.CameraType = Enum.CameraType.Scriptable
    --Functions
    print('received at',os.time())
    game:GetService("RunService").RenderStepped:Connect(function()
        Camera.CFrame = part.CFrame
    end)
end)

Using the following script:

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnClientEvent:Connect(function(part)
	--Player
	local Player = game:GetService("Players").LocalPlayer
	--Model
	local Model = workspace:FindFirstChild("PlayerCharacter")
	local HeadCamera = Model.Head
	local SecondCamera = Model.SecondCamera
	--ReplicatedStorage stuff
	local GameFunctionsModule = game:GetService("ReplicatedStorage"):WaitForChild("GameFunctions")
	--Camera
	local Camera = workspace.CurrentCamera
	Camera.CameraType = Enum.CameraType.Scriptable
	--Functions
	print('received at',os.time())
	game:GetService("RunService").RenderStepped:Connect(function()
		Camera.CFrame = part.CFrame
	end)
end)


The stuff still don’t work… I can give an edited repro file.

Then the :SetCoreGuiEnabled is probably causing it. Try putting it inside of the .OnClientEvent function.

Also, add a yield to the server script.

Simply. The local script event isn’t firing at all. I don’t know what’s happening. I will do the work-around now, because it’s driving me crazy. Thanks for everything you did here.

Yes, it isn’t firing because you are creating the connection after the event has been fired which is why you should handle everything to do with camera manipulation on the client, not the server. If someone takes a long time to load, they aren’t going to have the event fired which will cause them to be stuck wherever they are and the camera scene won’t play.

1 Like

Maybe the WaitForChild on the client causes it to define the Event after the event is actually fired
Try to move the FireAllClients to after the wait(1)