Click Detector Script Not Working

Hello Everyone! I recently followed a YT tutorial on how to make a click detector GUI.

script.Parent.ClickDetector.MouseClick:Connect(function()
game.Players.LocalPlayer.PlayerGui.Egg.Frame.Visible = true

end)

This is the error that I get
50%20AM
This script is to open a GUI on the click of the part.
(I am a very basic scripter, so I do not know much about click detectors)
(This script may be outdated)
Thank you!

Please show us an image of the hierarchy/directory for the click detector .

You’re using a server script to control a GUI element, which is wrong, GUIs are supposed to be controlled from the client, in other words from a local script.

And personally, a very good advice: never copy paste scripts. It’s a bad habit, and you honestly won’t learn anything, you’re better of to make an attempt using what you already know, if it failed or you’re stuck, ask for help!

2 Likes

Information is missing; this does not look like a complete error. What I would assume though is that you’re getting a nil value error.

Where are you writing this from? If you aren’t using a LocalScript, LocalPlayer will be nil. No functions or methods will exist for it, considering its a reference to the current player that’s blank.

This a local script yes? And did you put it under Workspace? I’m assuming the parent of the ClickDetector is a brick/part. Unfortunately local scripts don’t work under Workspace.

1 Like

I’ve tested it and it works 100% , I just made it
here’s the code, Server Script ofcourse, in the part, as in this specific case you require for there to be one part, just one, and for there to show a gui on clicking it,
and make sure Egg is a screengui and is called just that and is parented to StarterGui and has the child, Frame called Frame and is set to visible=false

Here’s my code :

function onClicked(playerWhoClicked) 
	local playerWhoClicked = playerWhoClicked
	playerWhoClicked.PlayerGui.Egg.Frame.Visible=true
	
	end


script.Parent.ClickDetector.MouseClick:connect(onClicked)

But remember , unless you don’t script this by yourself, you’ll become dependent on others for scripts.
**Edited , this version is shortened, reducing memory consumption

3 Likes

You have too much fluff in your function. You can remove a lot of that unnecessary work and memory consumption with a direct call.

local function onClicked(playerWhoClicked)
    playerWhoClicked.PlayerGui.Egg.Frame.Visible = true
end

You shouldn’t be handling Guis from the server anyhow. ClickDetectors and likewise Gui interaction can be managed from the client and they should be.

3 Likes

6 posts were merged out for being off-topic

Just touching on the solution providers script. It can be shortened.

script.Parent.ClickDetector.MouseClick:connect(function(player)
player.PlayerGui.Egg.Frame.Visible=true – this won’t work on the server though. You’ll need a remote event to make this happen, so you can connect over to the client side.

make_visible()

End

Sorry for not indenting it properly. I’m on my phone.

1 Like