I'm making an ORB in a game and I don't know how to make it so if your camera is in it's line of view, it runs a piece of code. This obviously needs to be Local, not for every player. Thanks!
Example:
Player looks at orb
Code runs
Player looks away from the orb
code stops
You can try using WorldToScreenPoint function. It checks if a part's position is visible on the screen.
This code snippet utilizes that function to destroy a part.
01 | local camera = workspace.CurrentCamera |
02 | local humanoid = script.Parent:WaitForChild( 'Humanoid' ) |
03 | local part = workspace.ORB |
04 | local inView = false |
05 |
06 | repeat |
07 | local iView = workspace.CurrentCamera:WorldToScreenPoint(part.Position) |
08 | if (iView) then |
09 | inView = true |
10 | end |
11 | wait( 2 ) |
12 | until inView = = true |
13 |
14 | if inView = = true then |
15 | part:Destroy() |
16 | end |