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

How do I CFrame a part to the character's head?

Asked by 4 years ago

So I'm trying to make a gravity game where the camera is always attached to the players head, even if upside-down. I've tried this code just for the movement of the camera (will add angles later) but it does not attach to the head as required.

local campart = workspace.CameraPart
local player = game.Players.LocalPlayer
local torso = player.Character.Head
local offsetCFrame = Vector3.new(7, 0, 0)

latch.CFrame = torso.CFrame:ToWorldSpace(offsetCFrame)

The code needs to just 'weld' the camera to the player's head with an offset of about 7 studs. If anyone can help I would be very grateful. And if you don't understand something, comment about it and I will clarify.

0
maybe change line 6 to `latch.CFrame = torso.CFrame + offsetCFrame` Leamir 3138 — 4y
0
no, that didn't work, the output mentions on line 3 'attempt to index nil with 'Character'' MuffinZMan_YT 20 — 4y
0
you need to wait for the character to be loaded, just add `repeat wait() until game.Players.LocalPlayer.Character` Leamir 3138 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Constantly set the CFrame ok good thanks

local Camera = workspace.CurrentCamera
local p = game:GetService("Players").LocalPlayer


game:GetService("RunService").RenderStepped:Connect(function()
    if p.Character then
        local Attach = p.Character:FindFirstChild("Head")
        if Attach then
            Camera.CFrame = Attach.CFrame
        end
    end
end)

Give upvote

0
ok yes but now how do i add the offset MuffinZMan_YT 20 — 4y
0
nvm i did it MuffinZMan_YT 20 — 4y
Ad

Answer this question