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:
local Camera = workspace.Camera
local part = workspace.Enemies.Chaser.UpperTorso
local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)
while wait(0.1) do
if withinScreenBounds then
print("looked")
end
end
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.

1 comment
use workspace.CurrentCamera