-------------------------


local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local timerStarted = false
local UIS = game:GetService("UserInputService")
local Values = script.Parent:WaitForChild("Values")
local car = script.Parent.Car.Value
local DriveSeat = car:WaitForChild("DriveSeat")
local Started = car:WaitForChild("Started")
local Update = car:WaitForChild("Update")
local Tune = require(car:WaitForChild("A-Chassis Tune"))
local Model = script.Model.Value
local IsOn = Values.Parent:WaitForChild("IsOn")


IsOn.Changed:Connect(function()
	if IsOn.Value then
		Started:FireServer(Model, IsOn)
	else
		Started:FireServer(Model, false)
	end
end)

DriveSeat.ChildAdded:Connect(function()
	if Tune.AutoStart == true then
		Started:FireServer(Model, true)
	else
		Started:FireServer(Model, false)
	end
end)

DriveSeat.ChildRemoved:Connect(function()
	
	Started:FireServer(Model, false)
	
end)

Values.RPM.Changed:Connect(function()
	Update:FireServer(Model, "RPM", Values.RPM.Value, Tune.Redline)
end)

Values.Gear.Changed:Connect(function()
	
	Update:FireServer(Model, "Gear", Values.Gear.Value)
	
end)

local cs = coroutine.create(function()
	while wait() do
		if speedUnit == "KPH" then
			script.Speed.Value = math.floor(char:WaitForChild("HumanoidRootPart").Velocity.Magnitude)
			Update:FireServer(Model, "Speed", math.floor(script.Speed.Value * ((10/12) * 1.09728)))	
		elseif speedUnit == "MPH" then
			script.Speed.Value = math.floor(char:WaitForChild("HumanoidRootPart").Velocity.Magnitude)
			Update:FireServer(Model, "Speed", math.floor(script.Speed.Value * (10/12) * (60/88)))
		end	
	end
end)
coroutine.resume(cs)																																																																																																																																																																																																																																																																																																																																																																																																	
