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

How do you weld a ship with hundreds of parts together with a script so it can move?

Asked by 9 years ago

I am trying to weld a pirate ship together with code so that it can move through the water. Unfortunately I haven't been able to figure out the right coding. I have tried many different codes but they don't seem to work. Such as: w = Instance.new("Weld") w.Part0 = _____ w.C0 = ____.CFrame:inverse() w.Part1 = script.Parent w.C1 = script.Parent.CFrame:inverse() w.Parent = script.Parent

The boat needs to be all welded together and unanchored.

3 answers

Log in to vote
0
Answered by 9 years ago

You'll need to run a loop welding and indexing all the parts, and then after the parts are indexed, unanchor them.

Something like this-


Parts = -- Place where all the blocks are Engine = -- Main block

Get = {}

for _,v in pairs(Parts:GetChildren()) do if v:IsA("BasePart") then table.insert(Get,v) if v ~= Engine then local Weld = Instance.new("Weld") Weld.Part0 = Engine Weld.Part1 = v Weld.C0 = CFrame.new() Weld.C1 = v.CFrame:inverse() * Engine.CFrame Weld.Parent = Engine end end end

wait()

for _,v in pairs(Get) do v.Anchored = false end

0
It says Workspace.Deck.Script:6: attempt to index global 'Parts' (a nil value) KMANGEL 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

A shorter way

local prev
for _,v in ipairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then
        if prev ~= nil then
            local w = Instance.new("Weld")
            local a = v.CFrame:inverse()
            local b = prev.CFrame:inverse()
            w.Part0 = v
            w.Part1 = prev
            w.C0 = a
            w.C1 = b
            w.Parent = v
            v.Anchored = false
        end
        prev = v
    end
end
Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

Use the SIXWELDIT plugin. Make sure they are unanchored otherwise it will not move.

Answer this question