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

How do I make this teleportation Script not reset rotation?

Asked by 5 years ago

Whenever I teleport, the rotation of the player is reset

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    Key = Key:lower()
    if Key == 'e' then
        local humroot = game.Workspace[Player.Name]:FindFirstChild("HumanoidRootPart")
        humroot.CFrame = CFrame.new(humroot.Position.X + 50, humroot.Position.Y, humroot.Position.Z - 30)
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

Your script seems a little out of the ordinary; I'll give you another simpler one that you can use for reference.

So instead of moving the player's humanoid around using CFrames (used in camera positions), you can use vectors (which are the same thing but for moving around objects such as blocks or players). You can do this by moving the player's character. The player's character is actually a grouped model in workspace with the player's name (game.Workspace["Player's name"]). Grouped models are a bit different from normal parts in game. Rather than using "game.workspace["Player's name"].position", you use "game.workspace["Player's name"]:MoveTo()".

Here's an example as follows:

local plr = game.Players.LocalPlayer --The localplayer
local Mouse = Player:GetMouse() --Gets the mouse

Mouse.KeyDown:connect(function(key) --The function you used to get what key the player pushed
    Key = Key:lower() --Makes sure the the key is turned lower case
    if Key == 'e' then --Checks if the key "e" is pressed
        plr.Character:MoveTo(Vector3.new(x, y, z)) --The player's character (game.Workspace["Player's name"]) is moved to a vector in which the coordinates are as follows: x, y, z
    end
end)

If you have any problems or questions please contact me. ;)

Ad

Answer this question