Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Creates tracks for wheels and their hinges
- if Stats.TrackInfo.EnableTracks.Value == true then
- local LeftWheel = 1
- local RightWheel = 1
- local TracksFolder = Instance.new("Model")
- TracksFolder.Name = "Tracks"
- TracksFolder.Parent = script.Parent.Parent
- local TrackData = Stats.TrackInfo
- for i,v in pairs(Wheels.LeftWheels:GetChildren()) do
- local Wheel1 = Wheels.LeftWheels:FindFirstChild("Left"..tostring(LeftWheel))
- local Wheel2 = Wheels.LeftWheels:FindFirstChild("Left"..tostring(LeftWheel+1))
- if Wheel1 and Wheel2 then
- local Track = Instance.new("Part")
- local WheelDistance = (Wheel1.TrackConnection.Position - Wheel2.TrackConnection.Position).Magnitude
- Track.Size = Vector3.new(WheelDistance+0.2, TrackData.Thickness.Value, Wheel1.WheelWeld.Size.X + TrackData.WidthModifier.Value)
- local TrackPos = Wheel1.TrackConnection.Position + 0.5*(Wheel2.TrackConnection.Position - Wheel1.TrackConnection.Position)
- local TrackVector = (Wheel1.TrackConnection.Position - Wheel2.TrackConnection.Position).Unit:Cross(Vector3.new(0,1,0))
- Track.CFrame = CFrame.new(TrackPos, TrackPos+TrackVector)
- Track.Parent = TracksFolder
- Track.Color = TrackData.Color.Value
- Track.Material = TrackData.Material.Value
- Track.CanCollide = false
- -- Creates hinges
- local RearAttachment = Instance.new("Attachment")
- RearAttachment.Parent = Track
- RearAttachment.Name = "RearAttachment"
- RearAttachment.Position = Vector3.new(Track.Size.X/2, Track.Size.Y/2, 0)
- RearAttachment.Orientation = Vector3.new(0,-90,0)
- local FrontAttachment = Instance.new("Attachment")
- FrontAttachment.Parent = Track
- FrontAttachment.Name = "FrontAttachment"
- FrontAttachment.Position = Vector3.new(-Track.Size.X/2, Track.Size.Y/2, 0)
- FrontAttachment.Orientation = Vector3.new(0,-90,0)
- local RearAttachmentWheel = Instance.new("Attachment")
- RearAttachmentWheel.Parent = Wheel2.TrackConnection
- RearAttachmentWheel.Name = "RearAttachment"
- RearAttachmentWheel.WorldPosition = RearAttachment.WorldPosition
- local FrontAttachmentWheel = Instance.new("Attachment")
- FrontAttachmentWheel.Parent = Wheel1.TrackConnection
- FrontAttachmentWheel.Name = "FrontAttachment"
- FrontAttachmentWheel.WorldPosition = FrontAttachment.WorldPosition
- local FrontHinge = Instance.new("HingeConstraint")
- FrontHinge.Name = "FrontHinge"
- FrontHinge.Parent = Wheel1.TrackConnection
- FrontHinge.Attachment0 = FrontAttachmentWheel
- FrontHinge.Attachment1 = FrontAttachment
- local RearHinge = Instance.new("HingeConstraint")
- RearHinge.Name = "RearHinge"
- RearHinge.Parent = Wheel2.TrackConnection
- RearHinge.Attachment0 = RearAttachmentWheel
- RearHinge.Attachment1 = RearAttachment
- end
- LeftWheel = LeftWheel+1
- end
- for i,v in pairs(Wheels.RightWheels:GetChildren()) do
- local Wheel1 = Wheels.RightWheels:FindFirstChild("Right"..tostring(RightWheel))
- local Wheel2 = Wheels.RightWheels:FindFirstChild("Right"..tostring(RightWheel+1))
- if Wheel1 and Wheel2 then
- local Track = Instance.new("Part")
- local WheelDistance = (Wheel1.TrackConnection.Position - Wheel2.TrackConnection.Position).Magnitude
- Track.Size = Vector3.new(WheelDistance, TrackData.Thickness.Value, Wheel1.WheelWeld.Size.X + TrackData.WidthModifier.Value)
- local TrackPos = Wheel1.TrackConnection.Position + 0.5*(Wheel2.TrackConnection.Position - Wheel1.TrackConnection.Position)
- local TrackVector = (Wheel1.TrackConnection.Position - Wheel2.TrackConnection.Position).Unit:Cross(Vector3.new(0,1,0))
- Track.CFrame = CFrame.new(TrackPos, TrackPos+TrackVector)
- Track.Parent = TracksFolder
- Track.Color = TrackData.Color.Value
- Track.Material = TrackData.Material.Value
- Track.CanCollide = false
- -- Creates hinges
- local RearAttachment = Instance.new("Attachment")
- RearAttachment.Parent = Track
- RearAttachment.Name = "RearAttachment"
- RearAttachment.Position = Vector3.new(Track.Size.X/2, Track.Size.Y/2, 0)
- RearAttachment.Orientation = Vector3.new(0,-90,0)
- local FrontAttachment = Instance.new("Attachment")
- FrontAttachment.Parent = Track
- FrontAttachment.Name = "FrontAttachment"
- FrontAttachment.Position = Vector3.new(-Track.Size.X/2, Track.Size.Y/2, 0)
- FrontAttachment.Orientation = Vector3.new(0,-90,0)
- local RearAttachmentWheel = Instance.new("Attachment")
- RearAttachmentWheel.Parent = Wheel2.TrackConnection
- RearAttachmentWheel.Name = "RearAttachment"
- RearAttachmentWheel.WorldPosition = RearAttachment.WorldPosition
- local FrontAttachmentWheel = Instance.new("Attachment")
- FrontAttachmentWheel.Parent = Wheel1.TrackConnection
- FrontAttachmentWheel.Name = "FrontAttachment"
- FrontAttachmentWheel.WorldPosition = FrontAttachment.WorldPosition
- local FrontHinge = Instance.new("HingeConstraint")
- FrontHinge.Name = "FrontHinge"
- FrontHinge.Parent = Wheel1.TrackConnection
- FrontHinge.Attachment0 = FrontAttachmentWheel
- FrontHinge.Attachment1 = FrontAttachment
- local RearHinge = Instance.new("HingeConstraint")
- RearHinge.Name = "RearHinge"
- RearHinge.Parent = Wheel2.TrackConnection
- RearHinge.Attachment0 = RearAttachmentWheel
- RearHinge.Attachment1 = RearAttachment
- end
- RightWheel = RightWheel+1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement