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

[SOLVED] Pop-up GUI whilst touching brick?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by
FiredDusk 1466 Moderation Voter
7 years ago
Edited 7 years ago

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)
0
It works great! How do I accept your answer? shadow7692 69 — 7y
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 " ^ " FiredDusk 1466 — 7y
0
There's no up arrow :( shadow7692 69 — 7y
0
Do you see the "Accept Answer" button below this comments section? FiredDusk 1466 — 7y
View all comments (2 more)
0
No it just says 'report' shadow7692 69 — 7y
0
Well, that is weird. FiredDusk 1466 — 7y
Ad

Answer this question