How do you ACTUALLY make a loop that detects a player?

I’ve done tons of reading, and none of the posts has ever answered my question on this topic: How do you make a loop that can detect a player that may be touching an object and continues to touch it? Such as a treadmill. You may want the treadmill to turn off for example when the player stops touching it, but when they begin touching it again, you want it to turn on. The issue with everything I’ve read is that it’s not very accurate and doesn’t work. Using the various methods (workspace:GetPartsInPart() or a .Touched event) you end up with hitching where the script thinks the player is no longer touching the object because… they aren’t. When walking, the player leg picks up off the treadmill and no longer collides, thus triggering TouchEnded/no longer being included in the aforementioned functions.

If you wanted to circumvent this and make it a smooth operation, where the treadmill turns on and STAYS on while the player is actively running on it, is there a simple function that does this, or is this issue typically best solved by having an invisible part that is always in collision with the player, thus preventing the hitching.

Hopefully what I said was actually understandable and not complete word soup lol.

Just curious what solutions y’all have found, because this is an issue I have been reading on for awhile, and maybe I’m just really dumb and missing it, but man I need a better solution than what I have now: Don’t lol

You could use spatial queries which are more accurate and consistent.

Something for a treadmill would be:

workspace:GetPartBoundsInBox(Treadmill.CFrame * CFrame.new(0,3,0), Treadmill.Size, OverlappingParameters)

There’s a position offset to ensure the RootPart is in touch rather than arms/legs.

debounce
Yeah bro i have no idea why are you overthinking so much.