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

Help with making a Gui pop up when a part is touched?

Asked by 7 years ago

I need help making a Gui pop up when a part in workspace is touched. I tried to do it myself but it wasn't working. I restarted the script and I need help with the rest.

local customize = workspace.Custom customize.Touched:connect(function(hit)

end)

0
Thanks for your answers MrMetal13 19 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Something like this would work:

1local customize = workspace.Custom.customize.Touched:connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid") then
3        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
4        if Player then
5            Player.PlayerGui.ScreenGui.Enabled = true
6        end
7    end
8end)
Ad
Log in to vote
0
Answered by 7 years ago
1part = game.Workspace.partname
2gui = script.Gui
3 
4part.Touched:connect(function(hit)
5player = game.Players:GetPlayerFromCharacter(hit.Parent)
6if not player.PlayerGui.guinamehere then
7gui:Clone().Parent = player.PlayerGui
8end
9end)

This piece of code should work.

Change the variable part to the parts location that you want to activate the touched function.

Change the variable gui to the gui's location

Change guinamehere to the name of the GUI

If you'd like the part to remove the gui if its already open we can do this by adding something simple:

01part = game.Workspace.partname
02gui = script.Gui
03 
04part.Touched:connect(function(hit)
05player = game.Players:GetPlayerFromCharacter(hit.Parent)
06if not player.PlayerGui.guinamehere then
07gui:Clone().Parent = player.PlayerGui
08elseif player.PlayerGui.guinamehere then
09player.PlayerGui.guinamehere:Destroy()
10end
11end)

If this doesn't work please let me know any error(s) outputted and I'll help you fix it.

Answer this question