(This is a long post with 2 solutions depending on what the problem actually is. I think your code is trying to solve the problem I solve first, because it doesn't really do anything on its own. If you want to see how your original script was wrong, and how I fixed it (and made a new one (at the beginning) then read the steps I have written))
Theres a few errors here but nothing that isn't easily solvable.
The one problem that I found difficult was whether or not this Gui will appear on the Players screen (so needs to be in the backpack)
If this is the case, then you need to put the ScreenGui in ServerStorage and this is your code (the Clicked variable makes sure only the first person clicking it gets the Gui. Otherwise it would copy into everyones PlayerGui if they all clicked it.
Clicked = false
function OpenGUI(player)
if Clicked == true then return
else
ScreenGui = game.ServerStorage:FindFirstChild("ScreenGui")
ScreenGui:Clone().Parent = player.PlayerGui
Clicked = true
Frame = player.PlayerGui.ScreenGui.Frame
if Frame.Visible == false then
Frame.Visible = true
end
end
end
script.Parent.ClickDetector.MouseClick:connect(OpenGUI)
If you wanted a brick to show the Gui. Use a BillboardGui. I have little experience with them so check the wiki.
Heres the solution to your original script.
1) You need to define ScreenGui. So you need to create the path to it. So if the script is in "Part" with the Frame (which has the ScreenGui inside it) then you could say:
ScreenGui = script.Parent.Frame.ScreenGui
**2)**BUT, ScreenGuis do not have an enabled or visible property, you need to use a Frame to do this.
How your Gui should look is SCREENGUI has inside it a FRAME has inside it Labels and other things.
So when you've done this, you should define Frame, not ScreenGui as:
Frame = script.Parent.ScreenGui.Frame
**3)**Frames do have a Visible property so your if statement will now be:
if Frame.Visible == false
**4)**Frames do have an enabled property, but it would be much better to use the Visible property again if you want it to show up just once.
**5)**Finally, your event listener is wrong. MouseClick is the event fired by a click detector. Also, you need to say what the part is. You can either define it as "part = script.Parent" at the start (like I did with frame) or substitute script.Parent in for part on the connection line (which is what I opted to do)
It will now become:
script.Parent.ClickDetector.MouseClick:connect(OpenGUI)
THE FINISHED SCRIPT:
Frame = script.Parent.ScreenGui.Frame
function OpenGUI()
if Frame.Visible == false then
Frame.Visible = true
end
end
script.Parent.ClickDetector.MouseClick:connect(OpenGUI)
This should work now! If theres anything you don't understand just reply to this and I'll try to explain.
4 comments
Oh, I see now.
Now, if I was to send my friend a model of something with buttons that make the GUIs, like you showed me, would he have to remake the GUIs in his ServerStorage, or does that transfer with models? My guess is that it doesn't.
Probably not but you can just tell them to move it from a brick or something into the ServerStorage.
You could actually keep the screen GUI in the brick and clone it. just change game.ServerStorage:FindFirstChild etc to script.Parent.ScreenGui:Clone()