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

Weld Script being weird?

Asked by 9 years ago

So, I am writing a weld script for my rollercoaster car, and I will be able to use it for everything else. Anyway, It works, but for some reason, every piece go all weird, into weird places, but only on certain parts, not every piece. The code:

function weld(base, group)
    for i, v in pairs(group:GetChildren()) do
        if v ~= script.Parent.Welds then
local w = Instance.new("ManualWeld") 
w.Parent = base
w.Part0 = base
w.Part1 = v
w.C0 = (base.CFrame-v.Position)
        end
    end
end
weld(script.Parent.Brake, script.Parent)

I am not sure what is wrong... Any solutions, maybe?

0
edit so that is works please, i think you messed up the code block thing dragonkeeper467 453 — 9y
0
so do i... i thought i was just my computer at first. rollercoaster57 65 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

here use this weld script i use it all the time :)

function weld()
    local parts,last = {}
    local function scan(parent)
        for _,v in pairs(parent:GetChildren()) do
            if (v:IsA("BasePart")) then
                if (last) then
                    local w = Instance.new("Weld")
                    w.Name = ("%s_Weld"):format(v.Name)
                    w.Part0,w.Part1 = last,v
                    w.C0 = last.CFrame:inverse()
                    w.C1 = v.CFrame:inverse()
                    w.Parent = last
                end
                last = v
                table.insert(parts,v)
            end
            scan(v)
        end
    end
    scan(script.Parent)
    for _,v in pairs(parts) do
        --v.Anchored = false
    end
end

weld()
script:Remove()
0
so which is last and the parts? Im taking a guess and going to say last is the base part, correct? rollercoaster57 65 — 9y
0
Thank you! I just switched out "last rollercoaster57 65 — 9y
Ad

Answer this question