Still have questions? Join our Discord server and get real time help.
Log in to vote

What's a better way to approach this than the method I'm doing?

Asked by 6 months ago

Hello everyone!

I am making a camera script that follows the player, but at a set offset.

The execution for this seems pretty straightforward, as I have done this:

--This replaces the CameraScript found in StarterPlayerScripts

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local offset =,10,15)

local humanoidRoot = character:WaitForChild("HumanoidRootPart")

while true do
    local playerPos = humanoidRoot.Position 

    local cameraCFrame = + offset, humanoidRoot.Position)
    camera.CFrame = cameraCFrame


This method WORKS, however It's a little bit choppy as seen in this example.

Now this seems to be due to the fact that the loop has the wait element in this, meaning that the script stops very momentarily and isn't on a constant loop. However removing this wait element breaks the script entirely.

Is there a different way to approach this to yield the same result that I haven't thought of?

Any help would be appreciated! Thank you :)

1 answer

Log in to vote
Answered by
Ziffixture 5655 Moderation Voter Community Moderator
6 months ago
Edited 6 months ago

You can use RunService's .Heartbeat signal to run a block of code every Frame. This should allow you to properly render.

local RunService = game:GetService("RunService")

    --// Code

Answer this question