So, I’m trying to make a 2D camera, but I’m having trouble making the camera’s CFrame the same as the part. The Camera goes to the sky instead of the part.
Scripts
(Local script in StarterPlayerScripts)
Assuming I’m understanding the problem correctly, you’re wanting a part to constantly be 10 studs above the player, and the player’s camera to have the same CFrame as the part (looking down)
This code below should work if the “Cam” part is Anchored and it’s in a LocalScript
local RunServ = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Part = workspace.Cam
local Camera = workspace.CurrentCamera
local AddVector = Vector3.new(0,10,0) --This is how far above the block will go, read somewhere that setting this as a variable is more optimized than doing Vector3.new in the loop
RunServ.RenderStepped:Connect(function() --Renders every frame, more efficient than "while true do"
if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
Part.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position+AddVector,Player.Character.HumanoidRootPart.Position) --Sets the part's position (first parameter) and makes it look at the player's RootPart (second parameter)
Camera.CFrame = Part.CFrame --Sets the camera's CFrame to the part's CFrame
end
end)
Also, additional tip, you can do “while wait(0.01) do” instead of