--//Controller//--

Oxygen.Changed:Connect(function()
	TweenService:Create(
		OxygenDisplayBar,

		TweenInfo.new(
			0.5
		),

		{
			Size = UDim2.new(Oxygen.Value / PlayerStatsConfiguration.MaximumOxygenValue.Value, 0, 1, 0)
		}
	):Play()
end)

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	TweenService:Create(
		HealthDisplayBar,

		TweenInfo.new(
			0.5
		),

		{
			Size = UDim2.new(Humanoid.Health / Humanoid.MaxHealth, 0, 1, 0)
		}
	):Play()
end)

while true do
	if Player.Team == PlayingTeam then
		if Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
			if Oxygen.Value > 0 then
				Oxygen.Value = Oxygen.Value - PlayerStatsConfiguration.OxygenChangeValue.Value

			elseif Oxygen.Value <= 0 then
				Oxygen.Value = 0

				Humanoid:TakeDamage(PlayerStatsConfiguration.NoOxygenDamage.Value)
			end
			
			task.wait(PlayerStatsConfiguration.OxygenDecreaseTime.Value)

		else
			if Oxygen.Value >= PlayerStatsConfiguration.MaximumOxygenValue.Value then
				Oxygen.Value = PlayerStatsConfiguration.MaximumOxygenValue.Value

			elseif Oxygen.Value < PlayerStatsConfiguration.MaximumOxygenValue.Value then
				Oxygen.Value = Oxygen.Value + PlayerStatsConfiguration.OxygenChangeValue.Value
			end
			
			task.wait(PlayerStatsConfiguration.OxygenIncreaseTime.Value)
		end
	end
	
	task.wait()
end
