Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

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 royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited by royaltoe 4 years ago

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
0
Doesn't work Bunxrot 2 — 4y
0
I think you need to make it a local script Bunxrot 2 — 4y
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? haba_nero 386 — 4y
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. royaltoe 5144 — 4y
View all comments (5 more)
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 SoftlockedUnderZero 668 — 4y
0
So textbuttons work SoftlockedUnderZero 668 — 4y
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. DeceptiveCaster 3761 — 4y
0
You guys are free to edit my script and make it into a localscript. haba_nero 386 — 4y
0
Works, but needs to be in localscript Bunxrot 2 — 4y
Ad

Answer this question