Gui activating when Player looks at a part for X seconds

Hello everyone!:wave::slightly_smiling_face:

There are a few things that I don’t know how to make while I was making my horror game.

When a player is looking at a part for 10 seconds, it will fire a RemoteEvent, that will turn on a Gui with glitch effects. Then after another 5 seconds of looking at the part, the player’s screen will glitch even more, and the player gets a jumpscare and a badge.

The jumpscare and the Gui are already made. The only thing that is missing is the script.

Any help on how I could do this?

You could try binding a function to render step, that checks the dot product between where the camera is currently looking and the look vector between the camera to the part, and if the dot product is within your desired range you define a global timestamp and every time the render step function is called you check if the current time subtracted to that timestamp is 10 seconds or more and if it is, unbind the function and fire the remote event.

My best guess is if the player is in First Person, get their mouse and use Mouse.Hit, make a variable that’s false, use GetPropertyChangedSignal on Mouse.Hit, make a while loop that last for ten seconds, and then check if the variable that was made was changed (change the variable when get property changed signal is fired and make sure to check first if Mouse.Hit is still detecting the part with the same name.)

then you can fire a RemoteEvent and Check if the Remote Is fired from ServerScriptsService.