Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this GUI code work?

Asked by 9 years ago

Let me start by saying this is one of my first scripts. Below, I have before me a script I just made, but won't work. Honestly, that comes as no surprise to me. I am making a model, but needed pop-up scripts to work. First of all, what did I do wrong. Second of all, what should I use to make it pop-up only for the person that clicked it? I have my thing setup with Click Detector, Script, and Frame as children of Part, and ScreenGui child of Frame, and TextLabel child of ScreenGui.

function OpenGUI()
    if ScreenGui.Visible == False
        then
       ScreenGui.Enabled = True
    end

end


part.ClickDetector.mouse:connect (OpenGUI)

Now, I have just started in scripting, so sorry if this is so wrong it isn't even funny. Thanks for any help!

3 answers

Log in to vote
1
Answered by 9 years ago

(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") -- Find Gui
        ScreenGui:Clone().Parent = player.PlayerGui -- Clone it into the PlayerGui
        Clicked = true 
        Frame = player.PlayerGui.ScreenGui.Frame
        if Frame.Visible == false then -- This part isn't really needed. if only one person will see it, then just make it Visible in the ServerStorage so when it clones its visible straight away.
           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 -- (true/false need to be all lowercase)

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.

0
Oh, I see now. Samson554 25 — 9y
0
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. Samson554 25 — 9y
0
Probably not but you can just tell them to move it from a brick or something into the ServerStorage. MasterDaniel 320 — 9y
0
You could actually keep the screen GUI in the brick and clone it. just change game.ServerStorage:FindFirstChild etc to script.Parent.ScreenGui:Clone() MasterDaniel 320 — 9y
Ad
Log in to vote
1
Answered by
IcyEvil 260 Moderation Voter
9 years ago
function OpenGUI() -- Alright
s = Instance.new("ScreenGui") -- Define screen gui
s.Parent = game.Workspace.Part -- or whatever it is...
if s.TextLabel.Visible ==  false -- false is not False It has to be spelled as false, also, Text Labels/ Text boxes can only be visible
then 
s.TextLabel.Enabled = true -- same thing with true
end
end

part.ClickDetector.clicked:connect (OpenGUI)

Hope this helped!

0
Okay, thanks a lot! Samson554 25 — 9y
Log in to vote
0
Answered by 9 years ago

you gotta define what the screengui is, also the clickdetector u have to use the Clicked event not mouse, and u cant make Guis visible, u make frames and textlabels visible

Answer this question