Button on surfacegui wont teleport player to a position

Hi! I am trying to teleport a player when the press on the button to a part in the game. Its working on a ScreenGui but not on the SurfaceGui.
I’m using a local script.

Here is what I mean:

Video

21.6 MB file on MEGA

You have to download the video to play it :confused:

The scripts are the same

Script:

wait(1)
player = game.Players.LocalPlayer
button = script.Parent
local debounce = false

function helpme()
	if not debounce then

		debounce = true
		LowerTorso = player.Character.LowerTorso
		LowerTorso.CFrame = game.Workspace.part.CFrame -- change the "part" to where ever you want player  to go
wait(0)
	end
end
button.MouseButton1Click:connect(helpme)

while true do wait()
	debounce = false
	wait(0)
end

This is really annoying. Can someone help me.
Thanks

ScreenGui’s use Local Scripts but SurfaceGui’s usually use scripts on the server so

player = game.Players.LocalPlayer

won’t work on a server script

I forgot to mention I’m using a LocalScript

Just a comment, use HumanoidRootPart instead of LowerTorso so that R6 players can be tp’ed as well as R15.

You Can Use PlayerCharacter:MoveTo(Vecter3Position)
Here is a Simple Code:

local Player = game.Players.LocalPlayer
local Button = script.Parent
local CoolDown = false

local function Teleport(Position)
    if CoolDown then return end
    CoolDown = true
    Player.Character:MoveTo(Position) -- Move The Player's Character To The Position
    wait(5) -- CoolDown Time
    CoolDown = false
end

Button.MouseButton1Click:connect(function()
    Teleport(workspace.part.Position) -- Use a Vector3 Position.
end)

Where is it located? Local Scripts can’t be used server side

Thanks for the comment. My Game will not be using R6.

Screen Shot 2020-12-27 at 13.21.54

I’ll try it. Thank you


A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

Thanks but it is not working

Oh, do you think I could use RemoteEvents to do it?

Put The LocalScript In The PlayerScripts For This To Work. And Also Define The Button Variable.

Okay, Ill try that

(this for 30

Or just add a ClickDetector to the Part and use that to get the Player and teleport them

OMG
Thank you so much, this helped me alot :+1:t4:

Thanks again

1 Like

I’ll try that in the future. Thanks