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 gui teleport function?

So I'm trying to make it so that if a player touches a part, a button pops up When they press that button, it teleports that player. If you can, please post me a working script. If you just want to bug-fix mine, feel free:

local teleportbutton1 = script.Teleport1 -- don't know why I made this

script.Teleport1.TextButton.MouseButton1Click:connect(function(m) -- teleport the player when button pressed
	p = m.Parent:findFirstChild("Humanoid")
	if p ~= nil then
		p.Torso.CFrame = CFrame.new(0,8,9) 
	end
end)
game.Workspace.Teleport1.Touched:Connect(function() -- show the button
	teleportbutton1.Enabled = true
end)
game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
teleportbutton1.Enabled = false
end)

All of the parts & things are in the right place, and it's in a LocalScript

1 answer

Try this. You tried to reference the Torso inside of the Humanoid, but the Torso is located inside of the character.

local teleportbutton1 = script.Teleport1 -- don't know why I made this

script.Teleport1.TextButton.MouseButton1Click:connect(function(PlayerWhoClicked) -- teleport the player when button pressed
	local Character = PlayerWhoClicked.Character
	local P = Character:FindFirstChildWhichIsA("Humanoid")
    if P ~= nil then
        Character:FindFirstChild("Torso").CFrame = CFrame.new(0,8,9) 
    end
end)

game.Workspace.Teleport1.Touched:Connect(function() -- show the button
    teleportbutton1.Enabled = true
end)
game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
teleportbutton1.Enabled = false
end)

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