Lava isn't breaking welds on touch

I am trying to make it where my Lava part breaks all welds when it touches parts because I want the buildings to collapse as the lava rises.

image
(the script gets enabled when the round starts)

WeldDestroy Script:

script.Parent.Touched:Connect(function(hit)
	if hit and hit.Parent and hit:IsA('Part') and not hit.Parent:FindFirstChild('Humanoid') then
		wait(1) -- Add a 5-second delay

		hit.Anchored = false

		for _, constraint in ipairs(hit.Parent:GetDescendants()) do
			if constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
				constraint:Destroy()
			end
		end

	else
		if not hit:IsA('Part') then
		elseif hit.Parent:FindFirstChild('Humanoid') then
		end
	end
end)

ISSUE:

the lava doesnt even break the welds on one of my maps, and on the others it seems to break only if a player is touching some parts in the map (for example sitting on the roof of a house, then the house collapses when the lava rises, but if no player is touching the lava it isnt collapsing)

this is probably simple but i am not good at coding in any way, so if anyone can help out i would be so thankful.

Hi! It seems that you are using .Touched to detect collisions between anchored parts. According to the official documentation, at least 1 part must be unanchored. I suggest you use workspace:GetPartsInParts() periodically to detect whether your Lava part is overlapping any parts, and destroy their Welds from there.

If you are using TweenService to tween your lava to rise, I’d suggest periodically checking with workspace:GetPartsInParts() and destroy the welds from there.

If you ARE using TweenService

I’ve written some code beforehand to test. Here’s the snippet:

local t = tweenService:Create(partToTween,ti,partPropt)
t:Play()


repeat
	task.wait(3)
	local parts = workspace:GetPartsInPart(partToTween)

	
	for _, overlappingParts in ipairs(parts) do
		for _, constraint in pairs(overlappingParts:GetDescendants()) do
			if constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
				constraint:Destroy()
			end
		end
		
	end
	

	partToTween.Touched:Connect(function(part) -- We can use the .Touched event here, since the Player is unanchored
		
		if part.Parent:FindFirstChildOfClass("Humanoid") then
			local hum = part.Parent:FindFirstChildOfClass("Humanoid")
			hum.Health -= hum.Health
		end
	end)
until t.Completed

1 Like

Maybe because you aren’t using BasePart? Try this.

script.Parent.Touched:Connect(function(hit)
	if hit and hit.Parent and hit:IsA('BasePart') and not hit.Parent:FindFirstChild('Humanoid') then
		task.wait(1) -- Add a 5-second delay

		hit.Anchored = false

		for _, constraint in ipairs(hit.Parent:GetDescendants()) do
			if constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
				constraint:Destroy()
			end
		end

	else
		if not hit:IsA('BasePart') then
		elseif hit.Parent:FindFirstChild('Humanoid') 
then
		end
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.