I need help with checking the camera

You can write your topic however you want, but you need to answer these questions:

  1. I want to make a sphere move forward if its not seen on the camera, but its not working.

  2. It isnt moving, or working.

  3. I have seen the original poster of this code’s post. But it didnt work.

Here is my code:

local part = workspace.SunCopy
local cam = workspace.CurrentCamera

local isOnScreen = select(2, cam:WorldToViewportPoint(part.Position))

local function myCode()
	script.Parent.Position = script.Parent.Position + script.Parent.CFrame.LookVector*3
end

while task.wait() do
	--check if on screen, if not, return end.
	if isOnScreen then
		myCode();
	else return end
end

I really dont get it, cause even if i look at it, it still moves.
image

It is causing the code to stop completely and not run when you look at it again, use continue instead

Dunno why you’d use select(). WorldToViewportPoint returns a vector and a boolean. You want the boolean which is if you can see the point or not so change the isOnScreen variable to this:

local vector, isOnScreen = cam:WorldToViewportPoint(part.Position)

ive done it but it hasnt worked. a really stupid question from me tho, is this supposed to be in startercharacterscripts/starterplayerscripts or no

oh yeah, and something really weird is happening where it cant find the sphere even though roblox corrects me. (nevermidn this problem has been fixed)