Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why wont this break welds?

Asked by 8 years ago
-- SETTINGS --

IsAnchored = false  -- Set this to true if you want to make it unable to move before breaking welds

Speed = 25 -- The ammount of speed (in SPS) you need to reach to break welds 

Remove = false -- Set this to true if you want to auto-delete destroyed blockade after a specified time.

RemoveTime = 10  -- How long (in seconds) before auto-deleting destroyed welds (if Remove is true)

-- SCRIPT --

local P         = script.Parent
local mainPart  = P.Main
local weldedParts = {}
table.insert(weldedParts,mainPart)

function Weld(x, y)
    local weld = Instance.new("Weld") 
    weld.Part0 = x
    weld.Part1 = y
    local CJ = CFrame.new(x.Position) 
    weld.C0 = x.CFrame:inverse() * CJ  
    weld.C1 = y.CFrame:inverse() * CJ  
    weld.Parent = x 
    table.insert(weldedParts,y)
end

function WeldRec(instance)
    local childs = instance:GetChildren()
    for _,v in pairs(childs) do
        if v:IsA("BasePart") then
            Weld(mainPart, v)
            script.Parent.Main.Anchored = IsAnchored
        end
        WeldRec(v)
    end 
end

WeldRec(P)

function onTouched(part)
    local h = part
    if h.Velocity.Magnitude >= Speed then
        script.Parent.Main:Destroy()
        wait(RemoveTime)
        if Remove == true then 
                for _,v in pairs(weldedParts) do
    if v:IsA("BasePart") then
        v:Destroy()
    end
end
        end

    end
end

script.Parent.Main.Touched:connect(onTouched)

This should, when a car hits it at over 25SPS, break all welds in a model.

0
Try using "weldedParts:BreakJoints" somewhere in the script KingPig999 13 — 5y

Answer this question