How do I make my vehicle weld properly?
This is my script:
03 | if (script.Parent.Parent:FindFirstChild( "VehicleSeat" )) then |
04 | local weld = Instance.new( "Weld" ) |
06 | weld.Part 0 = script.Parent.Handle |
07 | weld.Part 1 = script.Parent.Parent.VehicleSeat |
08 | weld.C 0 = script.Parent.Handle.CFrame:inverse() |
09 | weld.C 1 = script.Parent.Parent.VehicleSeat.CFrame:inverse() |
10 | weld.Parent = script.Parent.Handle |
11 | script.Parent.Parent.VehicleSeat.Anchored = false |
14 | for i,v in pairs (script.Parent:GetChildren()) do |
15 | if (v:IsA( "Model" )) then |
16 | if (v.Name = = "Hinge" ) then |
17 | local part = Instance.new( "Part" ) |
18 | part.Size = Vector 3. new(. 1 ,. 1 ,. 1 ) |
19 | part.Rotation = v.PrimaryPart.Rotation |
20 | part.Position = v.Wheel.Position |
21 | part.CanCollide = false |
22 | part.Parent = script.Parent |
25 | local weld = Instance.new( "Motor6D" ) |
27 | weld.MaxVelocity = 0.03 |
29 | weld.Part 1 = v.PrimaryPart |
30 | weld.Parent = v.PrimaryPart |
31 | for l,m in pairs (v:GetChildren()) do |
33 | if (m.Name ~ = "Wheel" ) then |
34 | local weld = Instance.new( "Weld" ) |
37 | weld.Part 1 = m.Parent.PrimaryPart |
38 | weld.C 0 = m.CFrame:inverse() |
39 | weld.C 1 = m.Parent.PrimaryPart.CFrame:inverse() |
40 | weld.Parent = m.Parent.PrimaryPart |
44 | local weld = Instance.new( "Weld" ) |
45 | weld.Part 0 = v.PrimaryPart |
46 | weld.Part 1 = script.Parent.Handle |
47 | weld.C 0 = v.PrimaryPart.CFrame:inverse() |
48 | weld.C 1 = script.Parent.Handle.CFrame:inverse() |
49 | weld.Parent = v.PrimaryPart |
50 | for l,m in pairs (v:GetChildren()) do |
52 | if (m.Name ~ = "Wheel" ) then |
53 | local weld = Instance.new( "Weld" ) |
56 | weld.Part 1 = m.Parent.PrimaryPart |
57 | weld.C 0 = m.CFrame:inverse() |
58 | weld.C 1 = m.Parent.PrimaryPart.CFrame:inverse() |
59 | weld.Parent = m.Parent.PrimaryPart |
66 | local parts = script.Parent:GetChildren() |
68 | 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 |
69 | if (prev ~ = nil and parts [ i ] .Name ~ = "Hinge" and parts [ i ] .Name ~ = "Hitch" ) then |
70 | local weld = Instance.new( "Weld" ) |
73 | weld.C 0 = prev.CFrame:inverse() |
74 | weld.C 1 = parts [ i ] .CFrame:inverse() |
81 | for i,v in pairs (script.Parent:GetChildren()) do |
82 | if (v.className = = "Part" or v.className = = "UnionOperation" or v.className = = "WedgePart" or v.className = = "Seat" or v.className = = "VehicleSeat" ) then |
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?