--Weld stuff here
--Engine

local ENG_PCK = nil
for i,v in pairs(misc:GetDescendants()) do
	if v:IsA("ObjectValue") and v.Name == "ENGINE_PACK" then ENG_PCK = v.Value end
end
if ENG_PCK then

	if ENG_PCK:FindFirstChild("Cam_Gears") then
		local CG = ENG_PCK.Cam_Gears
		for i,Gear in pairs(CG:GetChildren()) do
			if string.sub(Gear.Name,1,4) == "Gear" then
				MakeWeld(Gear.W,car.DriveSeat,"Motor")
				ModelWeld(Gear.Parts,Gear.W)
			end
		end
	end

	if ENG_PCK:FindFirstChild("Engine_Shake") then
		local ES = ENG_PCK.Engine_Shake
		MakeWeld(ES.W,car.DriveSeat,"Motor")
		ModelWeld(ES.Parts,ES.W)
	end

	if ENG_PCK:FindFirstChild("Manifold_Heat") then
		local MH = ENG_PCK.Manifold_Heat
		ModelWeld(MH.Parts,car.DriveSeat)
	end

	if ENG_PCK:FindFirstChild("Throttle_Body") then
		local TB = ENG_PCK.Throttle_Body
		for i,Body in pairs(TB:GetChildren()) do
			if string.sub(Body.Name,1,4) == "Body" then
				MakeWeld(Body.W,car.DriveSeat,"Motor",0.25)
				ModelWeld(Body.Parts,Body.W)
			end
		end
	end

	if ENG_PCK:FindFirstChild("Timing_Belt") then
		local TI = ENG_PCK.Timing_Belt
		ModelWeld(TI.Parts,car.DriveSeat)
		for i=1,#TI.Parts:GetChildren() do
			for x=1,#TI.Parts:GetChildren() do
				local Attachment = Instance.new("Attachment",TI.Parts["A"..x])
				Attachment.Orientation = Vector3.new(90,0,0)
			end
			local Beam = Instance.new("Beam",TI.Beams)
			Beam.Transparency = NumberSequence.new{
				NumberSequenceKeypoint.new(0,0),
				NumberSequenceKeypoint.new(1,0)}

			Beam.Name = "A"..i
			if TI.TextureID.Value ~= nil then
				Beam.Texture = "rbxassetid://"..TI.TextureID.Value
			end
			Beam.TextureSpeed = 0
			if TI.BeltWidth.Value ~= nil then
				Beam.Width0 = TI.BeltWidth.Value
				Beam.Width1 = TI.BeltWidth.Value
			end
			if i == #TI.Parts:GetChildren() then
				Beam.Attachment0 = TI.Parts["A"..i].Attachment
				Beam.Attachment1 = TI.Parts["A1"].Attachment
			else
				print("A"..i+1)
				Beam.Attachment0 = TI.Parts["A"..i].Attachment
				Beam.Attachment1 = TI.Parts["A"..i+1].Attachment
			end
		end
	end

	if ENG_PCK:FindFirstChild("Turbochargers") then
		local TC = ENG_PCK.Turbochargers
		for i,Turbo in pairs(TC:GetChildren()) do
			if string.sub(Turbo.Name,1,5) == "Turbo" then
				MakeWeld(Turbo.W,car.DriveSeat,"Motor")
				ModelWeld(Turbo.Parts,Turbo.W)
			end
		end
	end

end
