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

Why doen´t this script teleport the player?

Asked by 5 years ago

I have recently been making this script. It needs to teleport the player to a certain position however it doesn´t work.

script.Parent.MouseClick:Connect(function()
    local Pos = script.Parent.Parent.Parent.TeleportingBlock2
    game.StarterPlayer.StarterCharacter:MoveTo(Pos.Position)
end)

2 answers

Log in to vote
1
Answered by
Vathriel 510 Moderation Voter
5 years ago

Your script doesn't work because it's not moving the character.

StarterCharacter is a folder for objects to be placed inside of the actual character when it's loaded.

your actual movement command should look something like

game.Players.LocalPlayer.Character:MoveTo(Pos.Position)

Now, I must warn you that may act weird with replication, but this should get you on the right track.

0
Thanks, it solved the problem. AndriusTheGreat 140 — 5y
Ad
Log in to vote
0
Answered by
asadefa 55
5 years ago
Edited 5 years ago

The reason is that TeleportingBlock2 is an object. You need to get the position, to teleport to. Then you should use SetPrimaryPartCFrame()

script.Parent.MouseClick:Connect(function()
    local Position = script.Parent.Parent.Parent.TeleportingBlock2.Position
    game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(Position)
end)

Answer this question