OnTouch and TouchEnded help

How would i be able to detect if a player is on a part and standing still instead of walking but i tried using ontouch and touchended and once the player walks on the part it ends almost instantly how would i fix?

Adding a Debounce might help you.

idk how that would work i already added one and it would just make it do it every 0.2 seconds due to debounce

Don’t put the touch events on the part the player is walking on. Instead, make a second, non-collideable and invisible part above the ground and connect to that. The feet of the player constantly lift and drop, so they’re constantly triggering Touched and TouchEnded.

1 Like

There’s a method that can solve this I found about a week and a half previous to writing this. Here’s the link to it: Simple trick to make GetTouchingParts work with non-CanCollide parts

Specifically for detecting if a particular player is touching/is on that part, here’s code I derived directly from the above mentioned method, and added onto:

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   return results

local myPart = -- Path in workspace to the part to be checked
local player = -- Path in workspace to the player to be checked for

while true do
    local touchingParts = GetTouchingParts(myPart) -- Returns a table with all touching parts
    for i, v in pairs(touchingParts) do
        if v.Parent == player then
            -- Do whatever you'd like

Keep in mind that the above code will run approximately every 0.033 seconds, so you might want to add a debounce or something of the like depending on your use case, which thus far hasn’t been discussed.

Feel free to ask any questions, and I hope you have a good rest of your week.


Thanks! this will greatly help

1 Like