Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To Make A Teleporter Gui That Show When A Player Touch A Part?


Hi, I have a question, I've made a Teleport Gui for Players on Mermaid High and It's worked in a part that i made on December 2020 but when i change the Gui for another it's doesn't work.

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(hit)
	if Debounce == false then
		Debounce = true
		if hit.Parent:FindFirstChild("Humanoid") then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui
			script.ScreenGui:Clone().Parent = plr -- replace "ScreenGui" with the name of your ScreenGui
		end
		wait(1)
		Debounce = false
	end
end)

Also i changed the Name on ScreenGui in the script and stop working

When it's opened: https://gyazo.com/e3da7e8b5c4ed37bc965e4681ecb9548

When it's not opened: https://gyazo.com/49fc25b4c7b71fe68f30143bf85ea0d3

9 comments

0

Clarify what you're trying to do. Also check in the output for any error messages

0

Don't see any reason why this shouldn't be working, maybe make sure of your screengui being visible look at your explorer to make sure it actually doesn't get placed in your playergui

0

Ok, Ty

0

The Gui doesn't are in the player gui, What i do?

0

plr.PlayerGui

0

Must be in the Player gui or no?

0

For a GUI to display for a player, it has to be in PlayerGui. If you put your GUI in StarterGui it'll automatically put it in PlayerGui, then you can use the Enabled property on the ScreenGui to enable and disable it.

0

Okie. Tysm

0

But the Gui doesn't show when touch a part

2 answers

FIXED CODE

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(hit)
    if Debounce == false then
        Debounce = true
        if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
            local PlayerGui = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui
            PlayerGui.ScreenGui.Enabled = true
        end
        game.RunService.Heartbeat:Wait()
        Debounce = false
    end
end)

EXPLANATION

on line 9 make sure to change ScreenGui to the name of yours.

swapped the

wait(1)

with

game.RunService.Heartbeat:Wait()

I think run service might be good in this situation. You should never use wait(n) or wait() because it can be really bad for performance instead wait for events like what I did. There'll always be an event for different situations.

This discussion is preserved as it was. New answers, comments, and votes are closed.