--print("anti-sleep activate")
--[===[
while script.Parent do
	local waitTime = wait()
	if waitTime > 0.0000001 and IsCoupled.Value then --insurance
		LastPositions[NumberPositions]=nil
		table.insert(LastPositions,1,coupler.Position)
		local AveragePosition = Vector3.new()
		for i = 1, #LastPositions do
			AveragePosition = AveragePosition + LastPositions[i]/#LastPositions
		end
		local RateOfChangeOfAveragePosition = (AveragePosition-LastAveragePosition).magnitude/waitTime
		if LastRateOfChangeOfAveragePosition < WakeupThreshold and RateOfChangeOfAveragePosition >= WakeupThreshold then

			if not PGS and RateOfChangeOfAveragePosition > WakeupThreshold then
				for _,k in pairs (coupler.Parent.Parent:GetChildren()) do --this assumes the draft gear itself is welded to the train
					
					if k:IsA("BasePart") then
						if k:CanAwaken() then
							k:Awake()
						end
						break
					end
				end
			end
		end
		LastRateOfChangeOfAveragePosition = RateOfChangeOfAveragePosition
		LastAveragePosition = AveragePosition
	end
end
]===]