I've been trying to figure out how to make a script that detects how many players are touching a part at a time but what happens is it keeps printing "Touch ended:" and "Touch started:" and a part of the humanoid such as a leg or foot and keeps nonstop changing the number. The script is a server script inside of a part that is located in workspace. Here is the script:
local part = script.Parent
-- Create a BillboardGui
local bbgui = Instance.new("BillboardGui", part)
bbgui.Size = UDim2.new(0, 200, 0, 50)
bbgui.Adornee = part
bbgui.AlwaysOnTop = true
local tl = Instance.new("TextLabel", bbgui)
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
local numTouchingParts = 0
local function onTouch(part)
print("Touch started: " .. part.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(part)
print("Touch ended: " .. part.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
if someone is able to help me please let me know!

1 comment
You might want to look at BasePart:GetTouchingParts() https://developer.roblox.com/api-reference/function/BasePart/GetTouchingParts