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

Model Touched

Model Touched

Oct 01 2018, 2:31 AM PST

This code sample demonstrates how to connect the Touched event of multiple parts in a Model to one function.

local model = script.Parent

local function onModelTouched(part)
	-- Filter any instances of the model coming in contact with itself
	if part:IsDescendantOf(model) then return end
	print(model:GetFullName() .. " was touched by " .. part:GetFullName())
end

for _, child in pairs(model:GetChildren()) do
	if child:IsA("BasePart") then
		child.Touched:Connect(onModelTouched)
	end
end