I’ve tried many times but failed. What trying to achieve for example: when a part is visible on the players screen it changes the color of it. If you know how to make it please tell me. There was misunderstanding, I mean like this
The lines are the players FOV lines how much he can see
As you see in the first picture the part is not visible for him (a real player)
And if it is visible it will turn green for example (visible for the player)
Imagine u have a part in the workspace and the player (real player) is in first person view and if the part is on his screen it will turn green for example
You can use the method in the first reply but if you wan’t to actually make sure it is visible, (because :WorldToScreenPoint() does not account for other objects blocking said part) you would need another function.
local camera = workspace.CurrentCamera
local target = --the part your trying to detect
local _, visible = camera:WorldToViewportPoint(target.Position)
local blockingParts = camera:GetPartsObscuringTarget({target.Position}, {target})
if visible and #blockingParts == 0 then --if it's within screen bounds AND nothing else is blocking it then proceed
--change color
end
You would need to put the 2 lines inside the while loop so they will always be the latest value… Variables stay the same once you define them for the rest of the script unless they’re redefined. And since it’s more of a first person thing i recommend you use a renderstepped event instead of a while loop.
while task.wait(0.8) do
local _, visible = camera:WorldToViewportPoint(target.Position)
local blockingParts = camera:GetPartsObscuringTarget({target.Position}, {target})
if visible and #blockingParts == 0 then --if it's within screen bounds AND nothing else is blocking it then proceed
--change color
end
end