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

Can someone help me with my "Pop Up GUI" code? The GUI doesn't pop up.

Asked by 4 years ago
Edited by Ziffixture 4 years ago

I am trying to make a script where when you touch a certain part, a GUI pops up on your screen. However, it has not been working in thew actual game, and not in the playtest. Please help me! This is my code:

 script.Parent.Touched:Connect(function(hit)
    if hit.Name == "Left Foot" then
        game.StarterGui.Shop.Frame.Visible = true
    end
end)

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Please read this short article excerpt.

TL;DR:

StarterGui is not the authentic household of the GUI Objects, to actively modify the local User Interface, you have to access the PlayerGui container of a Player Object. Fortunately, the .Touched signal's Hit parameter can be used to pull a Player Object from the Instance of contact, which is a piece of your Character Rig.

local Players = game:GetService("Players")

local Part = script.Parent

local function OpenGui(Hit)
    local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
    if (Humanoid) then
        local Player = Players:GetPlayerFromCharacter(Hit.Parent)
        if (Player) then
            local PlayerGui = Player:WaitForChild("PlayerGui")
            local Shop = PlayerGui:WaitForChild("Shop")
            local Frame = Shop:WaitForChild("Frame")
            Frame.Visible = not (Frame.Visible)
        end
    end
end

Part.Touched:Connect(OpenGui)

If this works for you, don't forget to accept this answer!

0
It works, but only once. How would I make it so it works multiple times? Coppper_Chase 9 — 4y
0
What do you mean only once? Ziffixture 6913 — 4y
0
If I step on it, then close the gui, it doesn't pop up again when I step on it. Coppper_Chase 9 — 4y
0
How are you closing the GUI Ziffixture 6913 — 4y
View all comments (10 more)
0
I have an X Button script that makes the GUI invisible Coppper_Chase 9 — 4y
0
Make sure you're not making the Shop Gui invisible. Otherwise this will also cause the Frame to disappear regardless of the visibility. Ziffixture 6913 — 4y
0
Then how would I close it without using the X Button or making it invisible? Coppper_Chase 9 — 4y
0
Are you gonna respond? Coppper_Chase 9 — 4y
0
alright im going to bed see u tommorow if you answer Coppper_Chase 9 — 4y
0
Try the code above, check the output if it doesn’t work. Ziffixture 6913 — 4y
0
hang on Coppper_Chase 9 — 4y
0
wait nvm i know what u mean) Coppper_Chase 9 — 4y
0
i get nothing in the output when i open or close the gui Coppper_Chase 9 — 4y
0
can we solve this tommorow? I need to go to bed. Coppper_Chase 9 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

This problem was fixed by @Feahren, so thanks to them.

Answer this question