Why is BreakJoints not working When Primary Part is hit

What are is the other script in the Tsunami also, is the DestroyWeld on touch script the exact same as this:

local function on_touched(hit)
	print(hit.Name)
	if hit.Name:lower():match("primary")  then

		for _, p in pairs(hit.Parent:GetChildren()) do
			if p:FindFirstChildOfClass("WeldConstraint") then
				p:FindFirstChildOfClass("WeldConstraint"):Destroy()
			end
		end
	end
end

script.Parent.Touched:Connect(on_touched)

This is the script that worked with me.

Other script just forms and creates the Tsunami and yes I used the exact same script above in the destroy weld script

I’m assuming the part is anchored and that it’s position is being changed in the other script? If so, don’t use onTouched, use

script.Parent:GetPropertyChangedSignal("Position"):Connct(function()
     
    for i,v in ipairs(script.Parent:GetTouchingParts()) do

      if v.Name:lower():match("primary") then
		for _, p in pairs(v.Parent:GetChildren()) do

			if p:FindFirstChildOfClass("WeldConstraint") then
				p:FindFirstChildOfClass("WeldConstraint"):Destroy()
			end
		end
        end
	end
end)

I rememebr making this mistake when I started scripting. This doesn’t work like you expect. Lua reads it like this:

hit.Name == "Primary" --> false
"Primary2" --> true
"Primary3" -- never reached because above is true
...

NOT like this:
hit.Name == "Primary" --> false
hit.Name == "Primary2" --> false
hit.Name == "Primary3" --> true
...

1 Like

should I use else or change the names or just have em all one name?

You’d go with this:

if hit.Name:match("^Primary") then

The ^ means the string must be infront (left).

1 Like

Guess i learned something new too, lol

it still isn’t working…
image
these are the Primary parts within each destructible model which are all in the Coastal Map model in Workspace (Nothing is anchored btw)

What if they were all just called Primary? Why are they different?

The problem isn’t really the names, it’s more of that the tsunami doesn’t register or fire the touched function when it is getting touched, but perhaps he can try this code and see if it is working:

script.Parent:GetPropertyChangedSignal("Position"):Connct(function()
     
    for i,v in ipairs(script.Parent:GetTouchingParts()) do

      if v.Name:lower():match("primary") then
		for _, p in pairs(v.Parent:GetChildren()) do

			if p:FindFirstChildOfClass("WeldConstraint") then
				p:FindFirstChildOfClass("WeldConstraint"):Destroy()
			end
		end
        end
	end
end)

The issue with the script is the conditional statement used to check if the hit part is one of the “Primary” parts. The expression "Primary" or "Primary2" (and so on) always evaluates to "Primary", regardless of the value of the hit part’s name. Therefore, the script will always break the joints of the hit part, regardless of its name.

To fix this, you should use separate conditional statements to check if the hit part’s name is equal to each of the “Primary” names you want to target. Here’s an example:

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "Primary" or hit.Name == "Primary2" or hit.Name == "Primary3" or hit.Name == "Primary4" or hit.Name == "Primary5" or hit.Name == "Primary6" or hit.Name == "Primary7" or hit.Name == "Primary8" then
		hit:BreakJoints()
	end
end)

Ok so I figured out why the Tsunami wasn’t destroying anything and its because the Tsunami Wave Mesh is Anchored idk if this is a Roblox bug cause I don’t quite get why this is happening and I used my Original WaveDestructionScript that I made in the original post anybody know a solution to fix this???

anybody know how this can be fixed??? I put it in a normal part and it worked when I dragged it to the buildings and part wasn’t anchored btw…

ok so i welded the wave mesh to the ocean part and it still isn’t destroying…

The Original script works just fine its just for some reason the Tsunami wave mesh cant be anchored or welded because for some reason it wont work but when its unanchored and not welded it works it just flings around and stuff and doesn’t stick to the ground…

Anybody know why all the sudden now I cant break joints if the part with the break joints script in it is either welded or anchored…??? pls help!!! or is this a Bug???