ScreenGui not showing upon clicking a ClickDetector

Hi guys, I have problem with Click Detector. I want to make when you click part the screengui frame label will be visible.

Properties:

o
Code:

--Variable--
local Open = game.StarterGui.ScreenGui.MainFrame.Open
local Closed = game.StarterGui.ScreenGui.MainFrame.Closed  
local MartialLaw = game.StarterGui.ScreenGui.MainFrame.MartialLaw


--Main Code--
script.Parent.ClickDetector.MouseClick:connect(function()
game.Players.LocalPlayer.PlayerGui.ScreenGui.MainFrame.Open.Visible = true
end)

Output:

k

Thank you in advance.

1 Like

Alright so, there’s a few issues here.

First of all, that error didn’t originate from this Script - take a look a the stack trace and you’ll see it comes from a Plugin named GoodPlugin, with a Script named Plugin.

Secondly, StarterGui’s contents are cloned locally on join and the LocalPlayer doesn’t exist in a Script (that runs on the server) because the LocalPlayer is whom the LocalScript is running for.

You’ll want to integrate a RemoteEvent into here that a LocalScript Connects onto it’s OnClientEvent to make the Open TextLabel Visible. Then you’ll want to utilise the Player parameter from the MouseClick to FireClient the RemoteEvent.

Players.LocalPlayer is a variable only accessable by client (local) scripts. You could make a LocalScript in the ScreenGui, give it a reference to the ClickDetector (workspace.Open.ClickDetector) and a reference to the TextLabel (script.Parent.MainFrame.Open). Attach a MouseClick event to the detector and you should be good to go.

2 Likes

Thank you very much! :slightly_smiling_face:

Thank you! :slightly_smiling_face:

Can’t you just define the player inside the parenthesis?

script.Parent.ClickDetector.MouseClick:connect(function(player)

Then from there you can do:

player.PlayerGui.ScreenGui.MainFrame.Open.Visible = true

It’s usually a bad idea to handle client sided effects on the server. It causes more data to be transmitted over the client server boundary + all the issues that come with networking. In this case, it would be a better idea to handle this from a LocalScript because it’s just as easy as handling it from a server script.

Oh, then I have been doing this all wrong all this time.