-- Tweens volume for more dynamic shut off

local function TweenNumber(Object,FromNum,ToNum,Duration,ValueType,EndFunction,StartCFrame)
	spawn(function()
		for i=0,1,1/(Duration/0.03) do
			
			local NewN = FromNum * (1-i) + ToNum * i
			
			if ValueType == "AngularVelocity" then
				Object.AngularVelocity = NewN/100
			end
			
			wait()
		end
		
		if ValueType == "AngularVelocity" then
			Object.AngularVelocity = ToNum/100
		end
			
		if EndFunction then
			EndFunction()
		end
	end)
end

local function StartWheel()
	
	-- Tween the spin speed for the wheel
	TweenNumber(FerrisMotor,FerrisMotor.AngularVelocity,WheelSpeed.Value,StartUpTime,"AngularVelocity")
	
	wait(StartUpTime+WheelMaxRideTime.Value)
	
	-- Tween the spin speed for the wheel
	TweenNumber(FerrisMotor,FerrisMotor.AngularVelocity*100,0,StartUpTime,"AngularVelocity",function() IsMoving = false end)
end

local function DetectPlayer(Seat)
	if Seat.Occupant and IsMoving == false then
		IsMoving = true
		StartWheel()
	end
end

for i=1, #AllBaskets do
	local Basket = AllBaskets[i]
	
	for _,k in pairs(Basket:GetChildren()) do
		if k and k:IsA("Seat") then
			table.insert(BasketSeats,k)
		end
	end
end
