Why my teleportation UI script is not working?

About the issue.

I made a script that was supossed that when you touch a part in-game, an UI pops out and when you click okay on the UI, you would get teleported to a CFrame.

Construction of the code, etcetera.

The phisic model of the structure and how it looks.

image

image

How the UI is made, and how it visually looks.

image

image

The LUA code.

local Pad1 = script.Parent.TeleportPad1
local Pad2 = script.Parent.TeleportPad2
local TPGUI = game.ServerStorage.TeleportationGUI

Pad1.Touched:Connect(function(hit)
	TPGUI.Parent = game.StarterGui
	TPGUI.Frame.TextButton.MouseButton1Click:Connect(function()
		if hit.Parent:FindFirstChild('humanoid') then
			hit.Parent.UpperTorso.CFrame = CFrame.new(-986, 4.5, -1040)
			wait(0.4)
			TPGUI.Parent = game.ServerStorage
		end
	end)
end)

So I first made the local variables. Then I started with a “when body touched” function on hit, that moved the actual GUI parent to the StarterGUIs so it’s visible. Then if the player clicked on “Okie”, it connected with another function, that conditioned that if the player hits, it should find the first child called “humanoid”, and, then that the torso gets to the stated CFrame, it waits 0.4, and puts the parents of the GUI again the ServerStorage.

Solutions I have tried.

  • Removing “PGUI.Frame.TextButton.MouseButton1Click:Connect(function()”.

Extra information.

  • Nothing pops out of the output.
  • The UI doesn’t even appear.
3 Likes

Try moving the Position of the Head not the Torso see if that Works.
This happened to me once.

You’re setting the parent to game.StarterGui! Players cannot see StarterGui :slight_smile: You have to parent it to the player’s PlayerGui folder for them to see it.

2 Likes

Why are you parenting it to starter gui it needs to be patented to the player gui instead, it will error there and the rest of the code won’t run.

2 Likes

Also by the way it is ‘Humanoid’ not ‘humanoid’.

2 Likes
local Pad1 = script.Parent.TeleportPad1
local Pad2 = script.Parent.TeleportPad2
local TPGUI = game.ServerStorage.TeleportationGUI

Pad1.Touched:Connect(function(hit, player)
		if hit.Parent:FindFirstChild('Humannoid') then
                TpGui:Clone().Parent = player.PlayerGui
		end
	end)
end)

Then add a server script into the UI button and type the teleport code.

1 Like

And I think you need to put the GUI in ReplicatedStorage because you can’t access ServerStorage from client right?

1 Like

Well it depends, if it’s a server script doing the cloning then no because that can access server storage but if it’s a local script, which if in workspace would be surprising/not considered best practice then yes the gui would have to be moved to replicated storage. Just to be clear if it is a local script then change it as it will not work.

1 Like
if hit.Parent:FindFirstChild("Humanoid") then

Oops just spotted that mistake sorry I am doing this on phone. Let me change it. Also the “” and ‘’ do the same thing.

1 Like

There is no second parameter for the Touched event, it’s only the Part that it HIt

If you want to get the Player, you have to refer to the Player’s Character by using the GetPlayerFromCharacter() function

local Pad1 = script.Parent.TeleportPad1
local Pad2 = script.Parent.TeleportPad2
local TPGUI = game.ServerStorage.TeleportationGUI
local PlayerDB = {}

Pad1.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Player and not table.find(PlayerDB, Player) then
        table.insert(PlayerDB, Player)

        TPGUI:Clone().Parent = Player.PlayerGui
    end
end)

It would be a bad idea to take the GUI instead of cloning it

local Pad1 = script.Parent.TeleportPad1
local Pad2 = script.Parent.TeleportPad2
local TPGUI = game.ServerStorage.TeleportationGUI

Pad1.Touched:Connect(function(hit)
    local clonedGui = TPGUI:Clone() -- Clone it so it doesnt appear as nil if someone else is trying to use it
	clonedGui.Parent = game.StarterGui
	clonedGui.Frame.TextButton.MouseButton1Click:Connect(function()
		if hit.Parent:FindFirstChild('humanoid') then
			hit.Parent.UpperTorso.CFrame = CFrame.new(-986, 4.5, -1040)
			wait(0.4)
			clonedGui:Destroy()
		end
	end)
end)