How to detect when player steps off part with raycasting

Ah, so the Raycast is in the mine, not the player…

I assumed from the title that the raycast is in the player. When I reread the first post it wasn’t completely clear, but now I see what you’ve done.

So change the raycast to detect the parent of whatever hits it. If it’s a Humanoid then ‘arm’ the mine with the repeat until loop. When the Humanoid is removed it’ll trigger the Changed event and you can explode it.

1 Like

Ohhhh hoh ho ohohooho, ok ok ok o kok.
Sorry for the title not being clear. I will take into consideration on the feedback you gave me. I will test it later today.


Yo bro, it works for the most part, however, the ray doesnt detect when the player STEPS off… i check if a variable set as InstanceModel is the same as ray.Instance.Parent, and that all works, but when the player steps off, the ray goes nil and it doesnt do anything. And if i do

if ray then



because of the animations or something, right when i step on the mine, it explode

That’s why you start a repeat until name state changed loop as I showed in my first example.

repeat until name state Changed()
task.wait(.2 or however long you want to wait after the player leaves the mine)

You want the function to fire, then wait until the repeat until loop to keep the mine from exploding.
Don’t use if ray because that just works whenever there is a ray. You need the function to be fired whenever the object name the ray is hitting is changed. This keeps unnecessary loops from happening since it only fires when a player steps on, and even if 2 players step on it and one steps off it won’t blow up, but when the raycast doesn’t detect a humanoid (both players step off) then it blows up.