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)
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.
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).
BasePart is over all the parts and (set CanCollide off and transparency to 1)
BasePart holds the single script instead of many scripts in all the parts
BasePart can be duplicated to account for other parts
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)
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.