Teleport GUI only pops up once

Hello Robloxians, :wave:
I have encountered a scripting problem that has been stuck with me for a while now.
For some reason, my script is supposed to activate every time I touch the neon purple part.
As shown in the video it only worked once. When I closed the GUI. It did not work again. I did not use any destroy function.


What are my scripts and, where are they located?

There are 2 scripts. Scriptle, and Script. You can see their locations by the image below.

cheese


Scriptle:

local frame = script.Info

function showgui(part)
	local player = game.Players:playerFromCharacter(part.Parent)
	if part.Parent:findFirstChild("Humanoid") and player then
		if not player.PlayerGui:findFirstChild("Info") then
			local screengui = script.Info:clone()
			screengui.Name = "Info"
			screengui.Parent = player.PlayerGui
		end
	end
end

script.Parent.Touched:connect(showgui)

Script:

button = script.Parent
window = button.Parent


function onClicked(GUI)
	window:remove()
end

script.Parent.MouseButton1Click:connect(onClicked)


Please help me in any way and form. I’m not a really good scripter.
Thank you for reading!

3 Likes
button = script.Parent
window = button.Parent


function onClicked(GUI)
	window:remove()
end

script.Parent.MouseButton1Click:connect(onClicked)

So your problem here is that for one :remove I think the function is deprecated and instead of just cloning the UI every single time and waste memory, just make the UI not enabled and in this case your code will look like this.

--[[
  Keep in mind to put the gui in startergui, disable it and name it Info.
]]--

local frame = script.Info

function showgui(part)
	local player = game.Players:playerFromCharacter(part.Parent)
	if part.Parent:findFirstChild("Humanoid") and player then
		if not player.PlayerGui:findFirstChild("Info") then
           local Info = player.PlayerGui:WaitForChild("Info")
           Info.Enabled = true
		end
	end
end

script.Parent.Touched:connect(showgui)
3 Likes

Isn’t that deprecated? You have to use :Destroy() now

1 Like

Although :remove() is deprecated, it evidently still works and you should use :Destroy().

However, the issue is the fact that you’re deleting the frame and not the Info GUI, meaning that when the player touches the part again, it doesn’t make a new GUI as you already have an empty one called Info.

1 Like

It was his code that I put in the first code block.

1 Like

Also where is the Part placed?

1 Like

You should preferably use a RemoteEvent in ReplicatedStorage and then fire to the client if you want to do stuff such as when you touch a part and then a gui should be displayed.

1 Like

1st Reply

I tried @DaffyDavinko 's solution. There is no output error.
I put the Info GUI into StarterGUI and the script stayed in the original part.
The problem is that the GUI itself is not willing to be Enabled.
In StarterGUI:
starter
In Workspace:
Starter2
In Scriptle:

--[[
  Keep in mind to put the gui in startergui, disable it and name it Info.
]]--

local frame = game.StarterGui.Info

function showgui(part)
	local player = game.Players:playerFromCharacter(part.Parent)
	if part.Parent:findFirstChild("Humanoid") and player then
		if not player.PlayerGui:findFirstChild("Info") then
			local Info = player.PlayerGui:WaitForChild("Info")
			Info.Enabled = true
		end
	end
end

script.Parent.Touched:connect(showgui)

In Script:

button = script.Parent


function onClicked(GUI)
	button.Enabled = false
end

script.Parent.MouseButton1Click:connect(onClicked)


2nd Reply

@GoteeSign
It’s here.

For god don’t use any Remotes for this… you can just do showing the gui by magnitude and I think it is way better.

Example of local script:

local PartTP = workspace.Part
local Player = game:GetService("Players").LocalPlayer

game:GetService("RunService").Heartbeat:Connect(function() 
local mag = (PartTP.Position - player.Character.HumanoidRootPart.Position).Magnitude
if mag < 5 then --you can change the 5 to whatever distance
--show ui
else
--close ui
end
end) 

@Wrvel lemme know if this is gonna work for you :).

2 Likes

Also, I don’t think you should place guis in workspace, put them in StarterGui. Also, you can use a remote event to manipulate the guis in the client.

1 Like

You’re deleting the frame, not the GUI, simply fix the script with window:remove to

local button = script.Parent
local GUI = script:FindFirstAncestorWhichIsA("ScreenGui") --is faster than chaining a load of .Parent calls

button.MouseButton1Click:Connect(function()
  GUI:Destroy()
end)

PS, its generally good practise to make your outermost variables local

2 Likes

Thank you so much @caviarbro , and @metatablecatmaid . :happy3:
May God bless you both. Thank you for all the others who also tried to help! :happy1:

1 Like