GUI show on Brick Touch

Hello all,
I have written a script (for a lift) where a gui is shown once the player touches the part, with teleport buttons on (so you can travel to each floor). Once you click any of the buttons, it is set to make the frame inside the GUI invisible so you can walk around. However, once its gone invisible, it does not come back if any of the blocks are touched.

This is my script inside the parts to bring up the GUI

local GUI = game.ServerStorage.LiftGUI

script.Parent.Touched:Connect(function(hit)
	
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
  local plr = game.Players[hit.Parent.Name]
if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
   GUI:Clone().Parent = plr.PlayerGui

  end
 end
end)

This is my teleport script inside all of the buttons in the GUI (which does the teleport and also closes the GUI)


player = game.Players.LocalPlayer
button = script.Parent


function onClick()
	script.Parent.Parent.Visible = false

  local LowerTorso = player.Character.LowerTorso
 LowerTorso.CFrame = game.Workspace.lobbytp.CFrame
 
 end

button.MouseButton1Click:connect(onClick)

Any help would be great!

2 Likes

try change it to script.Parent.Parent.Visible = not script.Parent.Parent.Visible

No, that does not work. Surely that is still executing the same thing I said, except that it would bring the gui back if the button was pressed again. However the buttons are inside the frame that disappears when you teleport.

–the code you write only clone the gui when is touched and when is touched again if its cloned already it won’t do anything, you need to make it visible again when you touch it

mmmm try to add this below that

–when you touch the part you want to make visible that gui try to adapt this
if plr:FindFirstChild(“PlayerGui”) and plr.PlayerGui:FindFirstChild(GUI.Name).Visible == false then
plr.PlayerGui:FindFirstChild(GUI.Name).Visible = true
end

maybe will work

Do I add this additionally, or replace something else with it?

when you clone the gui its fine, add it below your stuff

local GUI = game.ServerStorage.LiftGUI

script.Parent.Touched:Connect(function(hit)

if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
local plr = game.Players[hit.Parent.Name]
if plr:FindFirstChild(“PlayerGui”) and not plr.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = plr.PlayerGui

end
—add it here sorry
end
end)

1 Like

This still does not work?..

This is what my script looks like:

If you could let me know whats wrong with this (if anything) that would be great :slight_smile:

2 Likes

So which part of this would fix it? To me, it just seems like a better way to organize. (sorry if this is really simple, scripting is not my forte!)

check this out.

–add this pseudo code in your part
local yourPart = place where is your part in workspace

local yourGui = where your gui is stored

yourPart.Touched:Connect(function(hit)
yourGui.Enabled = true
end)

–add this pseudo code in your button
local yourButton = place where the button is
local yourGui = where your gui is stored

yourButton.MouseButton1Up:Connect(function()
yourGui.Enabled = false
end)

–You can avoid repeating same script in all buttons with collection service also

Does that replace all of the code currently in the two scripts?

1-Dont make frame invisible, make THE GUI enabled propperty to false
2-You can ADD the GUI to player starter gui and make it disabled already
3-You enable GUI when part is touched and disable when you press a button or leave certain distance of the part you touched
4-The pseudocode is the logic of how you later proceed to code your stuff.
5-Try to rewrite your code using the pseudocodes and converting it to lua code.

Ok. I will give it a go. I must go now, but i will be back tomorrow (i use BST time). I will PM you tomorrow for help or how it goes… :slight_smile:

1 Like