Parts not interacting with .Touched

I want to make a ocean that rises and destroys a house by unanchoring the parts of the house.

The issue is that when the ocean rises, the parts of the house don’t unanchor and don’t even show up in the output console.

I tried making these scripts and looking for solutions but nothing worked and I don’t know why.

Script in ServerScriptService that moves the ocean up and back down:

wait(15)
print("go")
for i=1, 550, 1 do
	wait(0.01)
	game.Workspace.Ocean.Position = game.Workspace.Ocean.Position + Vector3.new(0, 0.1, 0)
end
wait(10)
game.Workspace.Ocean.Position = Vector3.new(0, -90, 0)

Script in the ocean part that check if it touched another part:

script.Parent.Touched:Connect(function(part)
	print(part)
	if part.Name == "HousePart" then
		part.Anchored = false
	end
end)

(I don’t know if it has to do with the actual properties of the blocks but if it does, the ocean is anchored, has CanCollide off, and has CanTouch on. The house parts are anchored, have CanCollide on, and have CanTouch on.)

2 Likes

In your output log do you see “HousePart” being printed in the output log?

print(part) --// Should print everything it touches.
1 Like

No I don’t see anything, not even other parts that aren’t part of the house.

1 Like

That is a problem that means that function does not run( OnTouch isn’t being fired )

1 Like

But it should be running right? Because it’s touching other parts when it rises.

1 Like

If It doesn’t print it means the OnTouch event isn’t being fired. You can debug further or check script to see if its disabled I recommend putting a print outside of the OnTouch event

print("Connecting Ontouch event to script.Parent")
script.Parent.Touched:Connect(function(part)

If that^ doesn’t print it’s likely the script is disabled or yielding before the you connect the event which would prevent the code from working as intended

1 Like

I just tested and it did print, so I think it’s an issue with the parts themselves, but I still don’t know what.

1 Like

Then this could just be a little typo check your spelling

	if part.Name == "HousePart" then

But…
I’m still concerned about why nothing prints inside of the event :face_with_monocle:
It should at least print something if the parts are touching.

1 Like

There is no typo and even if there was, it should still print the part before it does the if statement. If you have discord, I can actually show you what is going on in game. Me and my friend have been trying to solve this for like two days lol.

1 Like

Are they both Regular scripts?
Also why not just

local Ocean  = workspace.Ocean
Ocean.Touched:Connect(function(part)
1 Like

Yes they are both regular scripts.

1 Like

Anchored parts don’t register touches with other anchored parts, especially when manually moving it. Overall, using .Touched tends to vary pretty heavily, but if you want to use it, you’d probably have to make some the house unanchored. A solution you could use would be BasePart:GetTouchingParts(), but since it doesn’t work with CanCollide = false parts, I recommend you look at this post:

1 Like

This worked thank you so much!