Part That "Stalks" the Player

To put it short and simple, I’m trying to script a Part so that it will “follow” the player. By this I mean:

If the player is walking down a hallway and they look back, the part will be peeking around the corner, and will go back behind the corner after about a second. If the player walks over to where the part was, the part will no longer be there.

This is sorta like Identity Fraud’s “Stan”, but I only need the creeping around the corner part.

I haven’t tried anything yet (mostly because I’m a bad scripter), but I would think that the “moving back behind the corner” part would require CFrame, followed by a task.wait(), then a line that makes the part invisible, allowing it to CFrame somewhere else without being seen.

The part I need help with is the movement part. I’m not sure how I would have the part only move to corners while the player’s back is to it. This means if the player is looking at a corner, the part cannot spawn at that corner, and if the player looks back at the part, the part will go back behind the corner and disappear.

TL;DR: I want to script a part that “stalks” the player by appearing behind corners while the players back is turned. If the player looks back at the part, it will move quickly back behind the corner and disappear, ready to stalk the player again.

You could make a code which detects corners automatically, however what that could would look like is beyond me.

An easier alternative is for you to create a part at each corner the part should be able to spawn at, keep them in a seperate folder or something.

Once you need to move the part to a corner, loop through the list and find the closest one. To detect if the player is looking in said corner, raycast to the part associated with said corner from the players head. If it’s successful, that means the player can see it and the part should not spawn there. The movement can be completed using TweenService (roblox.com).

Maybe you can use the humanoid rotation and .Touched events to do this.

I think marking corners manually with a part of some sort and then using some fancy math on the players camera angle and the closest corner would work. The script would be pretty complicated, but it would look good.

I thought about that, but the issue is that my game has well over several thousand corners (it’s a maze game).

oh, in that case I am not sure. possibly you could detect when two parts collide at a 90° angle, but that would probably mark a ton of non corners as corners.

Maybe you could raycast… and raycast!

What i’m thinking is to Raycast to spot the player. If the player is not found when the ray hits a wall the script ray casts in the other 3 directions, and so on until it finds the player. If the number of times the script has raycast = 1 then the part will move in the opposite direction.

Hope this helps. :penguin:

Another problem. The maze is a mesh, meaning it will be detected as a solid box.