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

FireClient: player argument must be a Player object?

I'm trying to fire from server to client. The part I have in the workspace:

Workspace
	Part
		Script
		TextButton

And in the StarterGui:

StarterGui
	ScreenGui
		Frame
		LocalScript

The Script:

local button = script.Parent.TextButton
local remEvent = game:GetService("ReplicatedStorage").RemoteEvent

button.MouseButton1Click:Connect(function(player)
	remEvent:FireClient(player)
end)

The LocalScript:

local remEvent = game:GetService("ReplicatedStorage").RemoteEvent

remEvent.OnClientEvent:Connect(function(player)
	script.Parent.Frame.Visible = true
end)

So when a player clicks the text button I wan't the Frame to become visible for the player. The server script doesn't seem to understand what the player is, though I have to put the player there or I get an error "Argument 1 missing or nil". I have thought that I could maybe define the player with a "PlayerAdded" function, but I'm not sure if I want to use it there even if it works.

2 answers

✓ Accepted answer

You can't get the player who clicked the SurfaceGUI's button from the server! You should parent the SurfaceGUI to the StarterGUI, and to make it visible on the part, set the GUI's adornee to the part!

From there, you can just listen to the click, and make it invisible for the player, without needing to use a RemoteEvent since that your code is fully client sided!

-- Local script inside of the GUI
local button = script.Parent.TextButton

-- You connect to the mouse click and make the GUI invisible in the same script!
button.MouseButton1Click:Connect(function() 
	script.Parent.Frame.Visible = false
end)

2 comments

1

Thank you so much!!

0

Happy to help!

I think I solved it... kind of. My script worked with a Click Detector, but not with the text buttons, but I don't know why it is like that :/

1 comment

0

Check my reply, I'm sorry that I'm a bit late! The ClickDetector is a nice workaround, but you can make it simpler by just doing what I said!

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