Make group of parts unanchor on touch

How do i make the bridge fall if player steps on it?

local model = workspace.break1:GetChildren()

for i = 1, #model do 
	local weld = Instance.new("Weld")
	weld.Part0 = model[i]
	weld.Part1 = model[i+1]
	weld.Parent = model[i]
end
function OnTouch(part)
	h = part.Parent:FindFirstChild("Humanoid")
	if h then
		for i,v in pairs(script.Parent.Parent:GetChildren()) do
			v.Anchored = false
		end
	end
end

script.Parent.Touched:Connect(OnTouch)


local model = workspace.break1:GetChildren()

for i = 1, #model do 
	local weld = Instance.new("Weld")
	weld.Part0 = model[i]
	weld.Part1 = model[i+1]
	weld.Parent = model[i]
end
function OnTouch(part)
	h = part.Parent:FindFirstChild("Humanoid")
	if h then
		for i,v in pairs(model) do
            if v:IsA("BasePart") then v.Anchored = false end
		end
	end
end

script.Parent.Touched:Connect(OnTouch)


Doesn’t work

Try it now, I just edited it! My mistake

same error again, it says " Expected BasePart got Script for Weld:Part1. - Server - Script:6"

Ok, once again:

local model = workspace.break1:GetChildren()

for i = 1, #model do 
    if model[i+1] ~= nil and model[i+1]:IsA("Script") then continue end
	local weld = Instance.new("Weld")
	weld.Part0 = model[i]
	weld.Part1 = model[i+1]
	weld.Parent = model[i]
end
function OnTouch(part)
	h = part.Parent:FindFirstChild("Humanoid")
	if h then
		for i,v in pairs(model) do
            if v:IsA("BasePart") then v.Anchored = false end
		end
	end
end

script.Parent.Touched:Connect(OnTouch)

The problem was not the touched event, but the weldin.

error in the output, Workspace.break1.Script:4: attempt to index nil with ‘IsA’ - Server - Script:4

Edited, added an extra check lol

Expected BasePart got Script for Weld:Part0. - Server - Script:6

Hello, do you want the parts to still be in the same shape and just be unanchored or all the parts just fly everywhere?

Here is what I came up with:
You can’t unanchor a model, you have to go an unanchor all the parts of it. I had problems with the welds, so the individual pieces are just dropping (a little more realistic too).

local db = false

function OnTouch(part)
	local h = part.Parent:FindFirstChild("Humanoid")
	if h and not db then
		for i,v in pairs(script.Parent.Parent:GetChildren()) do
			v.Anchored = false
		end
	else
		return
	end
end

script.Parent.Touched:Connect(OnTouch)

–edit: explained it

1 Like

thanks, i tested it and it looks cool

If you are using it for something else that needs to fall all in the same piece, don’t anchor anything except one part, then weld everything to that “base part”. All you have to do from there is unanchor the basepart.