How to lock part cframe to camera without lags?


I’m making a game and in the picture you see a block that should be attached to the camera, but the problem is that this script affects the fps. Here’s my script:

local part = workspace.Part

game:GetService("RunService").Stepped:Connect(function()
	part.CFrame = game.Workspace.CurrentCamera.CFrame
end)
2 Likes

Make sure your part is anchored. Unanchored parts handled this way will cause a lot of lag.

Also you’re using the wrong thing to hook into. You want to explicitly call this function before the camera updates (otherwise you’ll see the part stuttering when you have full frame rate). This new method here allows you to specify the priority:

RunService:BindToRenderStep("PartMoving", Enum.RenderPriority.Camera.Value, function(step)
    -- Code
end)

Just a heads up, if you CFrame your part to the Camera’s exact CFrame, you wont see the part at all since you’re inside of it. Make sure to offset accordingly!



RunService:BindToRenderStep("PartMoving", Enum.RenderPriority.Camera.Value, function(step)
	a.CFrame = workspace.CurrentCamera.CFrame
	
end)

i fix the code but it lags anyways

Make sure your part is CanCollide = false as well.

image
here is the properties but it lags anyways

Then something else is causing the lag because I’m not having any problems on my end when using the same code. This could be a result of something else happening in your studio, poor PC performance, or an entirely different factor.

What’s the part size?

The part size is 50,50,50 and this is a mesh for volumetric lighting

If you make the part invisible does it stop the lag? Also can you defer whether it’s the part itself that’s lagging or if it’s your whole studio session?

robloxapp-20240727-0103100.wmv (926.9 KB)
im using it for make volumetric lighting, i cant make invisible


im using this part to make the lighting better

Yeah this kind of opened up a whole can of worms here.

What’s the tri count of that mesh?
Do you have “CastShadows” enabled or no?

it disabled, but are there any alternatives to make such lighting?

You can adjust exposure compensation, or use VOLUMIKA (paid), but no not really. Volumetric lighting is a seriously expensive task. If it was this easy then Roblox would have added it around a decade ago!