Help with rendering part with RunService

I want a part to be rendered in front of the camera and I’m using BindToRenderStep to achieve this, but I have an issue where the part would not be visible at some points:


Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Value = Player:WaitForChild("PlayerInfo"):WaitForChild("Values").Seeker
local Part = ReplicatedStorage.RenderPart:Clone()

local Name = "RenderFrame"
local Distance = 2


Part.Name = "BlackFramePart"
Part.Parent = workspace.CurrentCamera

function render()
	Part.CFrame = workspace.CurrentCamera.CFrame + Vector3.new(0,0,Distance)
end

Value:GetPropertyChangedSignal("Value"):Connect(function()
	if Value.Value == false then
		RunService:UnbindFromRenderStep(Name)
		Part.Position = Vector3.new(0,-50,0)
	else
		RunService:BindToRenderStep(Name,Enum.RenderPriority.Camera.Value,render)
	end
end)

RunService:BindToRenderStep(Name,Enum.RenderPriority.Camera.Value,render)

And this is how the part looks like:


I believe it’s because the angle is not right but I don’t really know how to fix it. Any idea?

Try CFrame.new(0,0,Distance), normally when something doesnt work like that its because its moving on the world space instead of local, and cframe fixes that for me

1 Like

I changed the formule and I fixed it, but thanks for help anyway