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

[SOLVED] Pop-up GUI whilst touching brick?

I am having trouble making a GUI pop up when the player is touching a part, but then the GUI disappears when the player is not touching the part.

The part that I want the player to touch and activate the GUI is called 'Part'. The GUI is called 'GUI'.

The tree goes like this, Workspace > Part > Script > GUI

This is the code I have so far:

script.Parent.Touched:connect(function(char)
    local player = game.Players:GetPlayerFromCharacter(char)
    if player and not player.PlayerGui.GUI then
        script.GUI:clone().Parent = player.PlayerGui
    end
end)

script.Parent.TouchEnded:connect(function(char)
    local player = game.Players:GetPlayerFromCharacter(char)
    if player and player.PlayerGui.GUI then
        player.PlayerGui.GUI:Destroy()
    end
end)

When I test, the GUI just doesn't come up on screen when I touch the part.

How do I fix this??

1 answer

✓ Accepted answer

I have left some comments for you to read. If this helped, please accept my answer :)

script.Parent.Touched:Connect(function(hit) -- The parameter would not be the character, it would be the part that touches script.Parent
    local player = game.Players:GetPlayerFromCharacter(hi.Parent) -- hit.Parent is the character
    if player and not player.PlayerGui:FindFirstChild('GUI')
        script.GUI:Clone().Parent = player.PlayerGui -- "clone()" should have a capital "C"
    end
end)

script.Parent.TouchEnded:Connect(function(hit) -- Also, connect should be with a capital "C".
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and player.PlayerGui:FindFirstChild('GUI') then
        player.PlayerGui.GUI:Destroy()
    end
end)

6 comments

0

It works great! How do I accept your answer?

0

You should see it at the bottom of my answer. You can also give an upvote by pressing the arrow that is pointing up like " ^ "

0

There's no up arrow :(

0

Do you see the "Accept Answer" button below this comments section?

0

No it just says 'report'

0

Well, that is weird.

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