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.
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
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
Use the SIXWELDIT plugin. Make sure they are unanchored otherwise it will not move.