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

How do I cframe a player in position when they touch a part?

Asked by
par1d 19
5 years ago

Hey, I was wondering how I'd make it so once a player touches a part the player moves ina position using c frame (e.g. facing forward), how would I do this? :)

0
You would need to change the player's HumanoidRootPart's CFrame based on its CFrame.LookVector Le_Teapots 913 — 5y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

CFrame can be used to rotate as well as move an object. You can try something like this:

local Part = workspace.Part
local Players = game:GetService('Players')


Part.Touched:Connect(function(otherPart)
    local Player = Players:GetPlayerFromCharacter(otherPart.Parent) -- use service to get player
    if Player then -- check if player
        local Character = Player.Character or Player.CharacterAdded:Wait() -- get character
        Character.HumanoidRootPart = CFrame = Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
    end
end)

Use the math.rad() to rotate the player accordingly, while still keeping the Player's position.

Ad

Answer this question