Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a GUI that teleports you to a part and teleports you back where you were standing?

I'm so confused, how do i make a gui that teleports you to a part and teleports you back where you were standing before.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
 game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.TPPart.position)
 wait (0.3)
 game.Players.LocalPlayer.character.Torsto.CFrame = CFrame.new(player.position)
end)

Any help would be appreciated

1 comment

0

Did you mean 1) player clicks button, teleport player to part, wait a few seconds, and then teleport back or 2) click button, teleport to part, click button again, teleport back to original position before being teleported to part

1 answer

✓ Accepted answer

Make sure to make this a LOCAL SCRIPT, not a script.

local player = game.Players.LocalPlayer
local HRP = player.Character: WaitForChild("HumanoidRootPart")
local button = script.Parent --change this the location of your button

local part = game.Workspace:FindFirstChild("TeleportPart")--Change this to location of your part

button.MouseButton1Click:Connect(function()
        --keep track of position before being teleported
        local originalPosition = HRP.CFrame

        --teleport the player by changing the position if it's humanoid root part to be the position of the part in game
	HRP.CFrame = Part.CFrame + Vector3.new(0,5,0)

        --wait 5 seconds
	wait(5)

        --teleport player back to original position
	HRP.CFrame = originalPosition
end

9 comments

0

Doesn't work

0

I think you need to make it a local script

0

No. You don't. Local scripts do stuff locally, so the other players wont see you teleport. Can I have your error that you got?

2

This SHOULD be a local script since it has an event to detect when the players gui button is clicked. The players position is changed on the server when you change it locally. It doesn't have to be a server script for that. I added some comments fto your answer for clarification.

0

Actually it can do just fine, the only time you need a localscript is if youre trying to use localplayer, use a text box, or anything that involved with the client

0

So textbuttons work

0

@royaltoe is correct. @TheLastHabanero is not. FilteringEnabled does not support preventing local position changes from replicating to the server. Position change is one of the only things that can successfully bypass FE because the LocalPlayer has full control over their position.

0

You guys are free to edit my script and make it into a localscript.

0

Works, but needs to be in localscript

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