FireAllClients() works but FireClient() does not

So I am trying to make an objective trigger. And I do it by touching a part, it fires a remote event and the local script handles the GUI and stuff. But my problem is that if I write FireAllClients() it works and every player will see it, which is fine but if I try to make it FireClient() I hear the objective sound but the GUI wont appear.

ServerScript in a part in workspace:

local rs = game:GetService("ReplicatedStorage")
local re = rs.RemoteEvents

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") and not debounce then
		debounce = true
		
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		re.ObjectiveEvent:FireAllClients(player, "Explore the daycare area.", 10)
		
		task.wait(10)
		
		debounce = false
	end
end)

LocalScript in StarterGui:

local rs = game:GetService("ReplicatedStorage")
local re = rs.RemoteEvents

local GUI = script.Parent.ObjectiveGui

local Sounds = workspace.Sounds
local ObjectiveSound = Sounds.NewObjectiveSFX

re.ObjectiveEvent.OnClientEvent:Connect(function(player, Objective, ObjectiveTime)
	GUI.Enabled = true
	ObjectiveSound:Play()
	GUI.ObjectiveText.Text = Objective
	task.wait(ObjectiveTime)
	GUI.Enabled = false
end)
1 Like

FireClient has an additional argument that dictates which player to fire the remote event for while OnClientEvent won’t pass that argument along, unlike OnServerEvent.

To put it more explicitly, what’s happening when you use FireClient instead of FireAllClients is that the first argument in the server-side script is used to determine which player to fire the event for. Your local script then receives "Explore the daycare area." as the player, 10 as the Objective, and nil as the ObjectiveTime. That probably throws off your script. Instead of passing the player object along.

To fix it, just take out the player argument from the function you’ve connected to ObjectiveEvent.

2 Likes

Thanks alot, now I understand how I can fix it in the future.

1 Like

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