Making a GUI invisible after stepping off a part

I want to make it so after I step off a part my GUI goes invisible and when I step back on the part it appears again. I think this has something to do with debounce, I’m just unsure. Some help would be great.

Script:

local TeleporterPart = game.Workspace.Teleporter.TeleporterPart

TeleporterPart.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.TeleporterGUI.Frame.Visible = true
	end
end)
2 Likes

I would suggest you to use region instead of touch event

1 Like

You should make the .Visible to false, not true. This is because setting the Visible to true will cause the Frame to become visible (appear). Let me know if there are also any errors.

You can use the TouchEnded event which fires after a part is no longer being touched.

1 Like

I will try doing that now. I will tell you if it works.

Didn’t even know that was a thing! I’ll try that.

Oh yeah, nevermind. I read your thing wrong. You should make it like this:

local TeleporterPart = game.Workspace.Teleporter.TeleporterPart

-- The script below will make your TeleporterGui Frame visible when the player starts touching the teleport part
TeleporterPart.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.TeleporterGUI.Frame.Visible = true
	end
end)

-- The script below will make your TeleporterGui Frame invisible when the player stops touching the teleport part
TeleporterPart.TouchEnded:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.TeleporterGUI.Frame.Visible = false
	end
end)
1 Like

I tried that just now. Got this error:

Note: You might have to add a debounce to your script like this
Its optional but you can add it if you want to

local TeleporterPart = game.Workspace.Teleporter.TeleporterPart
local debounce = false

TeleporterPart.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr and debounce == false then
        debounce = true
        plr.PlayerGui.TeleporterGUI.Frame.Visible = true
        wait(1)
        debounce = false
	end
end)
1 Like

Nevermind, made a mistake in the script. It worked, thanks!

1 Like

That’s probably because the part is touching another part that is not a player, like the Baseplate for example. This causes the “game.Players:GetPlayerFromCharacter(hit.Parent)” bit to error because you can’t get the “Player” of a Baseplate part, right?

So what you wanna do is check if the part that touches the brick has a Humanoid (this is because only players has humanoid).


local TeleporterPart = game.Workspace.Teleporter.TeleporterPart

-- The script below will make your TeleporterGui Frame visible when the player starts touching the teleport part
TeleporterPart.Touched:Connect(function(hit)
        if part.Parent:FindFirstChild("Humanoid") == nil then return end -- This bit causes the script to stop working because it detects parts that are not a Player's character
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.TeleporterGUI.Frame.Visible = true
	end
end)

-- The script below will make your TeleporterGui Frame invisible when the player stops touching the teleport part
TeleporterPart.TouchEnded:Connect(function(hit)
        if part.Parent:FindFirstChild("Humanoid") == nil then return end
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.TeleporterGUI.Frame.Visible = false
	end
end)
1 Like

Ok if it works please mark the most appropriate answer as the solution.