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
Just doesn't work
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
For this code it says It says Workspace.Deck.Script:3: attempt to index global 'Parts' (a nil value)
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
For this code, it doesn't come into any errors but does not work correctly
Please help with code and instructions. The boat needs to be all welded together and unanchored.