You should use RemoteEvents for this, because the server won't be able to directly access PlayerGui.
Make sure to have a RemoteEvent in ReplicatedStorage.
ServerScript:
local RemoteEvent = game:GetService('ReplicatedStorage'):WaitForChild('RemoteEvent')
local ClickDetector = script.Parent:WaitForChild('ClickDetector')
ClickDetector.MouseClick:Connect(function(plr)
RemoteEvent:FireClient(plr)
end)
You can put the LocalScript anywhere in StarterGui, just make sure it can access the Frame you're trying to interact with. In this case, i'll have the LocalScript as a child of the frame so it's easier.
LocalScript:
local RemoteEvent = game:GetService('ReplicatedStorage'):WaitForChild('RemoteEvent')
local Frame = script.Parent
local Enabled = false
RemoteEvent.OnClientEvent:Connect(function()
if Enabled == false then
Enabled = true
Frame.Visible = true
elseif Enabled == true then
Enabled = false
Frame.Visible = false
end
end)
This is very basic use of RemoteEvents, but you can do much more with it. If there are any problems with the scripts, please let me know.
If you want a better explanation, here are some links to the developer forum:
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events