1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local oGUI = script:FindFirstChild( "ScreenGui" ) |
3 | script.Parent.MouseClick:Connect( function () |
4 | local GUI = oGUI:Clone() |
5 | GUI.Parent = player.PlayerGui |
6 | end ) |
Im trying to make a button , where if you click it , a GUI pops up , but when i tested it , nothing happens and there are no errors , can anybody tell me what's happening ? (Local Script)
Your cloning the entire screen gui you need to clone just a single gui for a example try doing this
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local oGuI = game:GetService( "StarterGui" ).Guiyouwannaenable |
3 | script.Parent.MouseClick:Connect( function () |
4 | local GUI = oGUI:Clone() |
5 | GUI.Enabled = true |
6 | GUI.Frame.Visible = true |
7 | GUI.Parent = player.PlayerGui |
8 | end ) |
Do not do this though
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local oGuI = game:GetService( "ScreenGui" ).Guiyouwannaenable |
3 | script.Parent.MouseClick:Connect( function () |
4 | oGUI.Enabled = true |
5 | end ) |
the thing with that is you will have to reset for it to pop up and everybody will see it unless its a local script
The issue here is that you've got your local script inside workspace. Local Scripts don't run inside workspace so you'll need to parent it somewhere else. Local scripts will only run if it's a descendant of the Player's Backpack, Character Model, PlayerGui, PlayerScripts or the ReplicatedFirst service as you can see here.
I would recommend you to parent your local script inside StarterGui and simply just change your variables.
01 | local player = game:GetService( "Players" ).LocalPlayer |
02 |
03 | workspace.Part.ClickDetector.MouseClick:Connect( function () -- Make sure to change this to where your ClickDetector is located inside your part. |
04 |
05 | local oGUI = workspace.Part:FindFirstChild( "ScreenGui" ) -- Make sure to also change this to where your GUI is located inside your part. |
06 | if oGUI then |
07 | local GUI = oGUI:Clone() |
08 | GUI.Parent = player.PlayerGui |
09 | end |
10 | end ) |