Making a teleporter using a SurfaceGui Button

Problem: Currently, I am looking for someone who can help me script a teleporter using a SurfaceGui Button. That when you click the button you will be teleported to a part. I know that this is basic for those professional developers.

2 Likes

You might want to include some more information on how you have your teleporters set up, how you want them to work, etc.

Providing this little information is basically you asking someone to make something for you with absolutely no background context.

1 Like

@ScripterTutorials I’m very very sorry, I forgot to type it. I edited it.

Create a surface GUI in StarterGui and set the adornee property of that surface GUI to the part you want it displayed on.
Next, create a localscript as a child of the surface GUI text/image button and insert this code in it:

local Players = game:GetService("Players") 
local Player = Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()
local PartPosition = workspace:WaitForChild(PARTNAME).Position

script.Parent.MouseButton1Click:Connect(function)
Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(Vector3.new(PartPosition))
end)
2 Likes

@yasir10001 Whenever I click the button, it teleports me to the middle of the baseplate.

Are there any errors in the console?

There’s none.

Why are you constructing a new Vector3 out of an existing one? You could simplify this code a lot by just using the part’s original CFrame instead of making a new CFrame and vector3 every time.

local PartPosition = workspace:WaitForChild(PARTNAME).CFrame

script.Parent.MouseButton1Click:Connect(function)
Character:WaitForChild("HumanoidRootPart").CFrame = PartPosition
end)
1 Like

Try using

Character:MoveTo(PartPosition)

2 Likes

It worked well! Thank you, this really helps me improves my holo.

1 Like

I would also like to say if you’re teleporting to a place thats lets say inside a building you may want to use SetPrimaryPartCFrame so you aren’t going to have people landing on the roof.

https://developer.roblox.com/api-reference/function/Model/SetPrimaryPartCFrame

Have a look at this page and if you need any help, message me. :+1:

Please follow category guidelines in the future. This is not a place to ask for free scripts.

1 Like