Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

18:53:02.382 - FireClient: player argument must be a Player object?

I'm trying to make a brick where if you click it, it teleports you to another location, with a sound and a gui that fades to black, then back out and becomes inactive. But, also being able to go back to the other location you teleported from. I have a remote event, where it does the teleporting and activates the GUI. And I have a red and blue brick with click detectors in them.

basically if you click the blue brick (tpB) it takes you to the red brick (tpA), but before it does, it will have the gui fade in and play a walking sound (like walking down/up stairs), and then it teleports you, and the gui fades out.


-- variables
local TPs = game.Workspace.Teleports.Teleport1
local tpA = TPs.TeleportA
local tpB = TPs.TeleportB
local TPEvent = game.ReplicatedStorage.Events.TPClicked
local Player = game:GetService("Players").LocalPlayer
local tp = game.StarterGui.Teleport2.ScreenGui
local g = tp.ScreenGui.Frame


TPEvent.OnClientEvent:Connect(function() -- function
	-- prints whoever clicked the brick
	tp.Enabled = true
	for transparency = 0,1 do
		g.BackgroundTransparency = transparency + 1/0	-- for the gui
	end
	-- putting the sound somewhere around here...?
	local hum = script.Parent:FindFirstChild("Humanoid") -- calling on humanoid and root part below
	if hum then
	local hmr = script.Parent:FindFirstChild("HumanoidRootPart")
	if hmr then
		hmr.Cframe = tpA.Cframe -- teleporting the player to the location of TeleportA
	end
	for transparency = 0,1 do
		g.BackgroundTransparency = transparency - 1/0
	end
	tp.Enabled = false
	end
end)

This is a local gui called "Teleport2", located in StarterGui, has the screen gui + frame

-- Variables
local plr = game.Players
local TPEvent = game.ReplicatedStorage.Events.TPClicked
local CD = script.Parent


-- function
CD.MouseClick:Connect(function(player)
	print(player.Name.. " has clicked the part!") 
	TPEvent:FireClient(player) -- fires the event and idk what to put there
end)

This is the second script in the clickdetector of the blue brick, called TPClicked.

The problem is that it doesn't teleport you at all, and doesn't even show the frame fading in or out. It just says this: 18:53:02.382 - FireClient: player argument must be a Player object

Some pictures below (Gyazo links)

Here

Here

And here.

8 comments

0

Your problem is in the second script: local plr = game.Players You forgot to get the LocalPlayer from Players Service, so you will get a service itself instead the player. 

0

This is how you get the LocalPlayer: local plr = game.Players.LocalPlayer

0

And I suggest you should use :GetPlayer() instead of :GetChildren() to get the table of player from Players service

0

I see, I will try that

0

You can’t retrieve the LocalPlayer through a ServerScript

0

So it has to be a local script too?

0

Contact my discord @Ziffixture#0152. I have already found all your collateral issues too, I’m on mobile at the moment and it is difficult to format my explanation, It’ll make it faster for the both of us

0

Ok I did

1 answer

✓ Accepted answer

FireClient requires the Player Object as an argument to identify which client it is actually firing at. You passed game.Players which essentially gave the entire container that holds the Players. The function tried to use it as reference, and as you can see this is a Service Container so it lead to your raised exception.

You cannot call game.Players.LocalPlayer either since the Script is operating under the Server; it doesn’t have a Player Object. Trying to use the local Player Object in any situation like so, would then make the ServerScript redundant, which is required to operate the ClickDetector. So how do we work around this, and properly retrieve the respective Player to fire at?

This is quite easy, the MouseClick RBXScriptSignal returns the Player that actually fired the detector, this way, we tell the RemoteEvent who to properly fire to.

local ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function(PlayerClicked)
   --// RemoteEvent:FireClient(PlayerClicked, args...)
end)

EDIT:

In accordance to your questions, the additional problem that is occurring is the fact that the RemoteEvent doesn’t actually pass the Player Object as a parameter like it would if receiving a Server fire. So the parameter defined as "Player" within OnClientEvent is invalid. You can pass PlayerClicked where "Args..." stands, however, this practice would be redundant as we don’t actually need to do this! The Client receiving the signal already knows who who they are since it is running on them. We can primitively perform actions on them by referencing them through LocalPlayer.

local Player = game:GetService("Players").LocalPlayer

--[[ RemoteEvent.OnClientEvent:Connect(function()
   print(Player.Name)
end)]]

It’s crucial you play around with this; understanding the difference between the Client and Server, are very important aspects into developing a game. Without this general understanding, you may also experience some issues along the road with unrelated projects, as you’d be surprised how often these two actually need to communicate with each other. To start off with understanding what I just mentioned, take a look at “Arguments and Parameters", or look further into how Remotes work.

Remember to accept this answer if it helped!

6 comments

0

Okay I did that, it prints it out, but the client still doesn't work. And what do I put in args?? I'm confused

0

I just put plr where args went cause it messed up when i kept it as args

0

I put that there as just a way for you to recognize where to place additional arguments for future reference. You don’t actually put place it within the the line, you’ll get a SyntaxError. Just RemoteEvent:FireClient(PlayerClicked) will work fine.

0

Alright I did that at first, and left it empty, it prints and everything. But, it doesn't teleport you and the gui doesn't enable still

0

I took another look. The edit should explain

0

Okay sir, yes I know about the remote event, but all it does is print it instead of firing the client, and it doesn't say anything is wrong. So Idk what to do. I just want the gui to work and you're only helping me on the remote event. And the teleporting is not working, so the remote event isn't the only problem here.

This discussion is preserved as it was. New answers, comments, and votes are closed.