How would I make a part massless only when it's touching a specific part?

I’m trying to make a ball with a weight in the bottom hemisphere–when the ball touches water, the weight inside it keeps it upright. I figured the easiest way to do it would be to put an invisible, no-collision part inside the water that triggers the masslessness, and while I figured out how to disable the masslessness on touch, I haven’t figured out how to re-enable the masslessness when the touch ends.

Here’s the code I have for the part inside the water:

function onTouched(hit)
	if not hit or not hit.Parent then return end
	local human = hit.Parent:findFirstChild("Humanoid")
	if human and human:IsA("Humanoid") then
		human.Parent.Weight.Massless = false
	end
end

function onTouchEnded(hit)
	if not hit or not hit.Parent then return end
	local human2 = hit.Parent:findFirstChild("Humanoid")
	if human2 and human2:IsA("Humanoid") then
		human2.Parent.Weight.Massless = true
	end
end

script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(onTouched)

What would I do to re-enable the masslessness on touch end? If you have an idea that doesn’t require me to put this script in every “water” part (the part that goes in the water that triggers this) and only goes in the ball part itself, please let me know.

You should introduce a specific tag for this behavior and document the behavior when it’s applied to certain instances. Then you would tag all of the instances you wish to have this behavior.

Also, this is a bad practice to use Touched, TouchEnded events. Instead you should use a reasonable time interval (either via RunService events, or task.wait loop) with GetPartsInPart, GetPartBoundsInBox, GetPartBoundInRadius functions by providing proper OverlapParams.