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 8 years ago
Edited 8 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:

01script.Parent.Touched:connect(function(char)
02    local player = game.Players:GetPlayerFromCharacter(char)
03    if player and not player.PlayerGui.GUI then
04        script.GUI:clone().Parent = player.PlayerGui
05    end
06end)
07 
08script.Parent.TouchEnded:connect(function(char)
09    local player = game.Players:GetPlayerFromCharacter(char)
10    if player and player.PlayerGui.GUI then
11        player.PlayerGui.GUI:Destroy()
12    end
13end)

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
8 years ago
Edited 8 years ago

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

01script.Parent.Touched:Connect(function(hit) -- The parameter would not be the character, it would be the part that touches script.Parent
02    local player = game.Players:GetPlayerFromCharacter(hi.Parent) -- hit.Parent is the character
03    if player and not player.PlayerGui:FindFirstChild('GUI')
04        script.GUI:Clone().Parent = player.PlayerGui -- "clone()" should have a capital "C"
05    end
06end)
07 
08script.Parent.TouchEnded:Connect(function(hit) -- Also, connect should be with a capital "C".
09    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
10    if player and player.PlayerGui:FindFirstChild('GUI') then
11        player.PlayerGui.GUI:Destroy()
12    end
13end)
0
It works great! How do I accept your answer? shadow7692 69 — 8y
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 — 8y
0
There's no up arrow :( shadow7692 69 — 8y
0
Do you see the "Accept Answer" button below this comments section? FiredDusk 1466 — 8y
View all comments (2 more)
0
No it just says 'report' shadow7692 69 — 8y
0
Well, that is weird. FiredDusk 1466 — 8y
Ad

Answer this question