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

How do you weld a part to the camera?

Asked by 6 years ago

I know how to weld a part to the character but how do you do it for the camera?

What I've tried:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        local cam = workspace.CurrentCamera
        local human = char:WaitForChild("HumanoidRootPart")
        local part= Instance.new("Part")
        part.CFrame = human.CFrame * CFrame.new(0,.65,-1)
        part.Size = Vector3.new(1.5,.5,1)
        part.CanCollide = false
        local weld = Instance.new("Weld")
        weld.Part0 = human
        weld.C0 = human.CFrame:inverse()
        weld.Part1 = part
        weld.C1 = part.CFrame:inverse()
        weld.Parent = part
        part.Anchored = false
    end)
end)

I noticed that the part is in the camera (not seen on screen) in explorer for a few seconds and is removed.

1 answer

Log in to vote
0
Answered by 6 years ago

I believe that you'd have to keep constantly setting the part's CFrame to the camera's CFrame. If you'd like to do it to a model (multiple parts), you can use Model:SetPrimaryPartCFrame() but make sure to set the primary part of the model. It will look something like this:

while true do
    Part.CFrame = cam.CFrame --optional - you can add "+Vector3.new(x, y, z)" if you want an offset relative to the camera's CFrame.
end

or

while true do
    Model:SetPrimaryPartCFrame(cam.CFrame)
end
Ad

Answer this question