On touch script, but how can I do it, so it will react to specific part?

Well, I am trying to make an oxygen system, but I ran in other problem…

The problem is…


…that the part detects the whole character of person (or it will also other entities)
THE CODE I am using:

local part = game.Workspace.woer

local ChildDescentHead = game.Players.LocalPlayer.Character.PrimaryPart

local function onTouch(ChildDescentHead)
	if part.Touched then
	wait(1)
		script.Parent.Value -=1
		repeat until part.TouchEnded
	end
end

local function onTouchEnded(ChildDescentHead)
script.Parent.Value = 45
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

If I’m understanding right, you are trying to get the OnTouch event to only fire when a specific part touched the character’s primary part, right? In that case you might want to use:

Part.Touched:Connect(function(touchingPart)
if touchingPart.Name=="Part" then --Replace "Part" with the part's name you want to detect
	print("Part touching")
end)

You can refer to the Developer wiki: BasePart | Roblox Creator Documentation

1 Like

Shows error in Output: