Basically run a function that fires when the raycast result changes. If the result Part.Name is a mine and you walk onto it you then you can use an if statement to see if is changing from that Part to any other part or Terrain. Then Kaboom!!
Seems like you just need to increase the length of the raycast. If you have it 0.1 studs tall, it’ll probably deactivate immediately after activating because of walking animations moving legs away from the mine, causing the raycast to not detect anything. With a longer raycast (say, 5 studs), the entire character will be detectable by the mine, which will reduce the chances of detected body parts falsely moving away from the raycast due to animations.
You would need an active state for your land mines. User your RaycastResult to determine what instance is currently beneath your feat (Raycastresult.Instance) and if that instance is one of your land mines then set the land mines active state to true, once that same land mine is no longer detected, set the active state to false.
Use a :Changed() function to detect a change in this state, within that function check if this state has been changed to false, if it does, explode. (This will not trigger if the initial state is false).
Wouldn’t just checking for if the Changed state goes from Top (the mine’s name) to anything else work more easily?
Function Raycastresult Part.Name state Changed
if the name state changes to Top then
repeat until name state Changed()
task.wait(.2 or however long you want to wait after the player leaves the mine)
end
Kaboom!
end
Yeah, anything that represents change can be used in this case, I figured a state would be the easiest but use whatever you’re most comfortable with!
I am a bit confused here, where am i going to store the name of the instance the ray hits? If i use a variable, i dont think i can use :Changed() right?
But Raycastresult returns the actual Part, right?
If you check if Raycastresult Part.Name changed to Top that sets the repeat until loop starting, which will then repeat until the Raycastresult’s Part.Name changes to anything else, then it’ll explode.
Yo. I tried this. However, it wasnt working, so i did a test.
while not stepped do
task.wait()
local raycast = workspace:Raycast(originExplode, direction, rayParams)
if raycast then
print(raycast.Instance.Name
end
end
To make sure the name would stay the same while standing still. This is what happened.
As you can see, while im standing still, the ray scans Left leg and Right leg, while I am standing still. This is probably due to the animations, which will make it not practical to use.