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

How do I make my vehicle weld properly?

Asked by 8 years ago

This is my script:

local prev  
--weld seat
if(script.Parent.Parent:FindFirstChild("VehicleSeat"))then
local weld = Instance.new("Weld")
            weld.Name = "dd"
            weld.Part0 = script.Parent.Handle
            weld.Part1 = script.Parent.Parent.VehicleSeat
            weld.C0 = script.Parent.Handle.CFrame:inverse() 
            weld.C1 = script.Parent.Parent.VehicleSeat.CFrame:inverse() 
            weld.Parent = script.Parent.Handle
            script.Parent.Parent.VehicleSeat.Anchored = false
    end
--weld models
for i,v in pairs (script.Parent:GetChildren())do
    if(v:IsA("Model"))then
            if(v.Name == "Hinge")then
            local part = Instance.new("Part")
            part.Size = Vector3.new(.1,.1,.1)
            part.Rotation = v.PrimaryPart.Rotation
            part.Position = v.Wheel.Position
            part.CanCollide = false
            part.Parent = script.Parent
            part.Transparency = 1
            part.Name = "M"
            local weld = Instance.new("Motor6D") 
            weld.Name = "motor"
            weld.MaxVelocity = 0.03
            weld.Part0 = part
            weld.Part1 = v.PrimaryPart 
            weld.Parent = v.PrimaryPart
            for l,m in pairs (v:GetChildren())do
                m.Anchored = false
            if(m.Name ~= "Wheel")then
            local weld = Instance.new("Weld")
            weld.Name = "dd"
            weld.Part0 = m
            weld.Part1 = m.Parent.PrimaryPart
            weld.C0 = m.CFrame:inverse() 
            weld.C1 = m.Parent.PrimaryPart.CFrame:inverse() 
            weld.Parent = m.Parent.PrimaryPart
            end
            end
            else
            local weld = Instance.new("Weld") 
            weld.Part0 = v.PrimaryPart
            weld.Part1 = script.Parent.Handle 
            weld.C0 = v.PrimaryPart.CFrame:inverse() 
            weld.C1 = script.Parent.Handle.CFrame:inverse() 
            weld.Parent = v.PrimaryPart
            for l,m in pairs (v:GetChildren())do
            m.Anchored = false
            if(m.Name ~= "Wheel")then
            local weld = Instance.new("Weld")
            weld.Name = "dd"
            weld.Part0 = m
            weld.Part1 = m.Parent.PrimaryPart
            weld.C0 = m.CFrame:inverse() 
            weld.C1 = m.Parent.PrimaryPart.CFrame:inverse() 
            weld.Parent = m.Parent.PrimaryPart
            end
            end
        end
    end
end
--weld parts
local parts = script.Parent:GetChildren()
for i = 1,#parts do 
    if (parts[i].className == "Part" or parts[i].className == "UnionOperation" or parts[i].className == "WedgePart" or parts[i].className == "Seat" or parts[i].className == "VehicleSeat") then 
        if (prev ~= nil and parts[i].Name ~= "Hinge" and parts[i].Name ~= "Hitch")then 
            local weld = Instance.new("Weld") 
            weld.Part0 = prev 
            weld.Part1 = parts[i] 
            weld.C0 = prev.CFrame:inverse() 
            weld.C1 = parts[i].CFrame:inverse() 
            weld.Parent = prev 
        end 
        prev = parts[i] 
    end 
end
--unanchor
for i,v in pairs(script.Parent:GetChildren())do
    if(v.className == "Part" or v.className == "UnionOperation" or v.className == "WedgePart" or v.className == "Seat" or v.className == "VehicleSeat")then
    v.Anchored = false
end
end 

But it welds weird and looks like it has been in a car accident. I don't think it is the script because the model welds fine in a map that is just about empty. But when it is in a map that has a lot of terrain, and takes awhile to load, then it welds weird. How can I make it load properly?

Answer this question