How to make a player teleport when clicking an imagebutton

  1. What is the issue?
    I don’t know how to teleport a player from one position to the position of a part:

    I know the last part is wrong i just don’t know how to fix it
1 Like

You need to use CFrame for this, do you mind sending the code in a text format? I’d be happy to write it out with some notes.

2 Likes

Here you go:
local player = game.Players.LocalPlayer
local humanoid = player.Character:FindFirstChild(“Humanoid”)
local TextButton = script.Parent
local ImageButton = script.Parent.Parent.Parent.ImageButton
local Frame = script.Parent.Parent
local Part = game.Workspace.Part – the part i want the player to teleport to

TextButton.MouseButton1Click:Connect(function() – Clicking the text button will make the text button invisible and the image button visible
TextButton.Visible = false
ImageButton.Visible = true
end)

ImageButton.MouseButton1Click:Connect(function() --Clicking image button makes image button invisible and the frame and teleports player to another position
TextButton.Visible = false
ImageButton.Visible = false
Frame.Visible = false
humanoid.Position = Part.Position --this is supposed to teleport the player to the parts position

end)

1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local textButton = script.Parent
local imageButton = script.Parent.Parent.Parent.ImageButton
local frame = script.Parent.Parent
local part = game.Workspace.Part  -- the part you want the player to teleport to

textButton.MouseButton1Click:Connect(function() 
    textButton.Visible = false
    imageButton.Visible = true
end)

imageButton.MouseButton1Click:Connect(function() 
    textButton.Visible = false
    imageButton.Visible = false
    frame.Visible = false
    humanoidRootPart.CFrame = part.CFrame  
end)

Instead of using position, CFrame is alot more reliable, you can check out the documentation here;

:link: CFrame | Documentation - Roblox Creator Hub

Let me know if this worked! :happy1:

2 Likes

It doesn’t work, when i click on play (the textbutton) nothing happens, what is supposed to happen is that text button dissapears image button apears, then you click on the imagine button and all gui dissapears and teleport you to another position. I did record it but it doesn’t let me post it here.

I found something in the output but I don’t know what it means:

I don’t know if it needs to be a local script maybe?

1 Like

Yes, this needs to be a local script inside of your text button.

1 Like

It works!!!
Thank you, but could you tell me the difference between a local script and a normal one? I am new to scripting.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.