Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to Detect if a Player looks away from Part??

Asked by 1 year ago

Its simple. What I wish to do is run function when player looks away from a part.

1 answer

Log in to vote
4
Answered by 1 year ago
Edited 1 year ago

I would use WorldToScreenPoint() to accomplish this. Note that it only detects the middle of the part, but looking up something for that should work. A code example would be:

local  pos, vis = workspace.CurrentCamera:WorldToScreenPoint(workspace.YourPartName.Position)

print(vis)

Hope this helps!

0
vis is a boolvalue right?? Shounak123 461 — 1y
0
if so, I'll have to do a continuous loop to constantly keep checking if the player is looking at part right?? Shounak123 461 — 1y
0
Correct! The first value, "pos", is the position of the part. The second value, "vis", is a boolvalue to check if it is onscreen. You need a loop (this is in a LocalScript by the way) so I would recommend using .RenderStepped. LikeableEmmec 470 — 1y
Ad

Answer this question