Why does 'FireAllClients()' work for gui but 'FireClient()' does not?

Hi! So I have this gui and I want to control the visibility of it (not with .Visible but :TweenPosition()). ’

How it works: When a player touches a part, a gui comes from the corner telling them what they receive.

Problem: FireClient() and FireAllClients() work differently (I’m trying to use FireClient() because only the player who touched the part should see it).


Local script in gui:

	if visible == true then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel:TweenPosition(UDim2.new(0.842, 0, 0.44, 0))
		if visible == false then
			game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel:TweenPosition(UDim2.new(1.2, 0, 0.44, 0))

Regular script in part:

local clientEvent = game.ReplicatedStorage:WaitForChild("Received")

function onTouched(m)
	local p = m.Parent:FindFirstChild("Humanoid")
	if p ~= nil then
		p.Torso.CFrame = CFrame.new(34.25, 1.5, 2685.5) --Change the numbers here to the position you want the humanoid to teleport to.

When I use FireAllClients(), it works perfectly but with FireClient(), here’s the error I get:

Got any suggestions on how I can fix this issue?

remote:FireAllClients() doesn’t need any parameters (values you send it) in order to function, as it merely just invokes the remote to all clients.

remote:FireClient(player) however, is different. It fires the remote for only the user specified, and the parameter it takes is not optional. It expects a player instance to be passed through when you call it.

The reason you’re getting that error is because it’s unable to convert the value you passed to the type that it needs to work (a player.) (can an apple become an orange?)

Explanation aside, to fix this you just need to specify what player the remote should be fired to.

1 Like

I would’ve shorten the code you applied as:

local player = game.Players:GetPlayerFromCharacter(m.Parent)


Still, it worked perfectly. Thanks so much for your help!

1 Like

While that technically isn’t shorter it’s the better alternative if you intend to use the player object after ‘FireClient()’ is called.

1 Like