Help checking if enemy is on player's screen?
I'm trying to make a script that plays a sound when the player looks at a monster. After some research, I have this script here:
1 | local Camera = workspace.Camera |
2 | local part = workspace.Enemies.Chaser.UpperTorso |
3 | local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position) |
5 | if withinScreenBounds then |
The problem with this is that it only ever works after the player respawns. With the while loop it does the same thing, when the player respawns it will start looping. I've put this into a localscript located inside StarterGui. I've seen some people talking about raycasting but I'm not quite sure how to set that up. Is there any way to make the script above constantly check? Or an alternative? Any help would be appreciated.