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.
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)
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 :/