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

Opening A Gui When A Part Is Clicked?

I have a part that when clicked should open a ScreenGui named All, but it doesn't and I have forgotten how ClickDetectors work. LocalScript:

game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local click = script.Parent.ClickDetector
local gui = script.Parent.All

click.MouseClick:Connect(function()
	gui.Parent = game.Players.LocalPlayer.PlayerGui
end)

Any help is appreciated!

2 comments

0

ClickDetectors can only run via ServerScripts, 

0

how would i do it then?

1 answer

ClickDetectors do work in local scripts.

What you're doing wrong is placing your local script inside the ClickDetector. Local scripts only run in workspace if it is under the local player's character.

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack, such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts.
  • The ReplicatedFirst service

https://developer.roblox.com/en-us/api-reference/class/LocalScript

You should place the local script in game.StarterPlayer.StarterPlayerScripts. Don't forget to change the definition of click so that it doesn't use script.Parent as script.Parent is no longer the ClickDetector.

3 comments

0

the script isnt inside of a click detector

0

I meant inside a part that contains a ClickDetector. The local script still wont run since it is a descendant of workspace and not in the local player's character

0

oki

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