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

How do I make a brick face the same direction as the player?

Asked by 4 years ago

LookVectors/cframes make no sense to me, so can someone help explain this to me?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited by User#24403 4 years ago

part.CFrame = CFrame.new(part.CFrame.p, targetCFrame.p)

You can construct a CFrame with two Vector3s. The first one is the position of the part and the second one is the position that you want the part to be facing.

So if you want the part to always be facing the player you would do it like this:

local RunService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local part = Instance.new("Part")
part.Parent = workspace

RunService.RenderStepped:Connect(function()
    part.CFrame = CFrame.new(part.Position, character.PrimaryPart.Position)
       -- or if you want the part to be facing the same direction the player is facing then you would do this: part.CFrame = CFrame.new(part.Position, part.Position + character.PrimaryPart.CFrame.LookVector)
end)
Ad
Log in to vote
-1
Answered by
Fad99 286 Moderation Voter
4 years ago

local Brick = workspace.Part

while true do
    wait()
    Part.CFrame = CFrame.new(Part.CFrame.p,Game:GetService("Players").devisings.Character.HumanoidRootPart.Position)
end

the first parameter should be the position you want the part, the second parameter is what you want the part to face. in this scenario the parts position will stay fixed, but will constantly be facing you.

0
i know i could've used more variables for tidiness Fad99 286 — 4y
0
-1 for bad code, events could have been used instead, and you don't answer the question in the body User#24403 69 — 4y

Answer this question