Player idle on part

Hey developers, I need help making a script that detects if a player is standing on a part and if they left it thanks.

Your going to need to use the TouchEnded event, along with Touched event. Please ensure to debounce these to avoid getting multiple readings. You will need to check for humanoids and that it’s a valid player, that is not in the documentation for the TouchEnded event, so please do not copy and paste.

Documentation can be found here: Detecting Collisions | Roblox Creator Documentation

You could just use the :Touched and :TouchEnded events. Try this out and let me know if it works for your case.

local debounce = false -- Debounce so event doesn't fire many times
local part = script.Parent -- Define the part

part.Touched:Connect(function(hit)
	if not debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			print("Player stepped on part!")
			debounce = true
		end
	end
end)

part.TouchEnded:Connect(function(hit)
	if debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			print("Player stepped off part!")
			debounce = false
		end
	end
end)