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

How to Teleport?

Asked by 10 years ago

So i recently been working on a new thing for when someone clicks a GUI Button it teleports them, here's the code

function onClicked()
    script.Parent.Parent.Parent:Destroy()
    game.Workspace.Menu:Stop()
    game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
    game.Workspace:FindFirstChild("Torso").Cframe = Vector3.new(0, 50, 0)
end
script.Parent.MouseButton1Click:connect(onClicked)

Then here's the error

12:35:51.600 - Players.Player1.PlayerGui.Menu.Play.LocalScript:6: attempt to index a nil value
12:35:51.602 - Stack Begin
12:35:51.604 - Script 'Players.Player1.PlayerGui.Menu.Play.LocalScript', Line 6
12:35:51.605 - Stack End

I've tried changing stuff around to fix it but nothing works.

Also how do we freeze a player when they spawn then unfreeze them -> then teleport them? I know i can use wait(5) to give the script some time to unfreeze the player but there's no wiki to telling me how to freeze a player from moving during he play screen.

2 answers

Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

Your code is searching for Torso, but you're not searching for the player in the Workspace. Also, New CFrame is required in addition to a vector.

local plr = game.Players.LocalPlayer

function onClicked()
    script.Parent.Parent.Parent:Destroy()
    game.Workspace.Menu:Stop()
    game.Workspace.CurrentCamera.CameraSubject = plr.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
    game.Workspace[plr.Name]:FindFirstChild("Torso").CFrame = CFrame.new(Vector3.new(0, 50, 0))
end
script.Parent.MouseButton1Click:connect(onClicked)

Ad
Log in to vote
0
Answered by 10 years ago

You could also make the script locate JUST the player Model in the workspace, and use the MoveTo method. For example:

game.Workspace.PlayerName:MoveTo()

Answer this question