PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TouchEnded

Fired when a part stops touching another part. This event fires under similar conditions to those of /BasePart/Touched.

Parameters

Name Type Default Description

Code Samples


Touching Parts Count

This code sample creates a BillboardGui on a part that displays the number of parts presently touching it.

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)