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

How do I weld a boat together?

Asked by 8 years ago

I feel like I'm staring right in the face of the answer but yet I can't see it. I've read these Roblox wikis,

http://wiki.roblox.com/index.php?title=CFrame

http://wiki.roblox.com/index.php?title=Weld#Welding_together_two_existing_bricks

and I've tried this Script in a Model with the parts I want to weld together as childs of the Model,

local function weldBetween(a, b)
    local weld = Instance.new("ManualWeld", a)
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = a.CFrame:inverse() * b.CFrame
    return weld
end

local weld = weldBetween(game.Workspace.BoatModel.a, game.Workspace.BoatModel.b)

but I can't figure anything out. I'm making a boat--I need the parts to stay in their relative positions to each other but be able to move around the game like a real boat.

I found a free model in the Toolbox called MasterWeld that apparently would weld all the pieces in a Model together using a weldAll statement...but that didn't work. The code in MasterWeld is as follows:

-- MasterWeld by Zephyred
-- Works for all types of parts, unions etc.
local exclude = {"Wheel"} -- Any object whose name is in this list will not be welded, for example          wheels.

function WeldPair(x, y)
    local weld = Instance.new("Weld",x) 
    weld.Part0 = x
    weld.Part1 = y
    weld.C1 = y.CFrame:toObjectSpace(x.CFrame);
end

function WeldAll(model, main) -- model can be anything
    for i,v in pairs(exclude) do if (model.Name == v) then return end end
    if model:IsA("BasePart") then WeldPair(main, model) end
    for _,v in pairs(model:GetChildren()) do WeldAll(v, main) end   
end

function UnanchorAll(model) -- model can be anything
    if (model:IsA("BasePart")) then model.Anchored = false end
    for _,v in pairs(model:GetChildren()) do UnanchorAll(v) end
end

WeldAll(script.Parent, script.Parent.Part)
UnanchorAll(script.Parent)

script:Destroy() -- Done, clean script up.

I don't have a lot of background knowledge in scripting but I'm pretty sure I meet the prerequisites in the Welds ROBLOX wiki page. :V

I really just need to stick this thing together and move on with making my game. Please please help.

2 answers

Log in to vote
0
Answered by 8 years ago

Group all your parts into a model and anchor it. Next insert this script - https://www.roblox.com/qPerfectionWeld-Perfect-welding-for-EVERY-situat-item?id=181259635

Ad
Log in to vote
0
Answered by 8 years ago

I find that joining parts using compatible surfaces would do the trick, (I.E. Weld = Smooth or Inlets = Studs) but may be a hassle if you have a a lot of parts

Or you could switch it's Join behavior to "Always" where it will join all parts even if the surfaces are smooth. Although, I found that when it was enabled, I had welds being created whenever I moved a part and had it touch another.

Answer this question