local function E(E,e,Z,B,J,T,H)spawn(function()for B=0,1,1/(B/.03)do local T=e*(1-B)+Z*B if J=="\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121"then E.AngularVelocity=T/100 end wait()end if J=="\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121"then E.AngularVelocity=Z/100 end if T then T()end end)end local function e()E(FerrisMotor,FerrisMotor.AngularVelocity,WheelSpeed.Value,StartUpTime,"\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121")wait(StartUpTime+WheelMaxRideTime.Value)E(FerrisMotor,FerrisMotor.AngularVelocity*100,0,StartUpTime,"\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121",function()IsMoving=false end)end local function Z(E)if E.Occupant and IsMoving==false then IsMoving=true e()end end for E=1,#AllBaskets,1 do local e=AllBaskets[E]for E,e in pairs(e:GetChildren())do if e and e:IsA("\083\101\097\116")then table.insert(BasketSeats,e)end end end
-- 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
