--[[
game.Workspace.Player.Humanoid.Running:Connect(function(speed)
    if speed > 1 and Bleeding.Value == true then
		 Blood.Value = (Blood.Value - (MLs.Value/30))	
	end
		
	if speed > 1 and bbleeding.Value == true then
		 Blood.Value = (Blood.Value - (MLs.Value/30))	
	end
	
	end)

]]
--


function ChangeBBleeding()
	if Config.SurgicalEnabled then
		bbleeding.Value = true
	else
		bbleeding.Value = false
	end
end


local BR = Config.BleedingRates

while Config.EnableMedSys do
	step = rs.Heartbeat:Wait()

	if Bleeding.Value == true then
		if Stances.Tourniquet.Value == false then -- no tourniquet
			Blood.Value = Blood.Value - MLs.Value * BR[1] * step
			MLs.Value = MLs.Value + BR[2] * step
		else -- with tourniquet
			Blood.Value = Blood.Value - MLs.Value * BR[3] * step
			MLs.Value = MLs.Value + BR[4] * step
		end
		if Stances.skit.Value == true and (BR[3] ~= 0 or not Stances.Tourniquet.Value) then -- starter iv kit
			Blood.Value = Blood.Value - MLs.Value * BR[5] * step
		end	
		MaxBlood = Blood.Value
	end

	if bbleeding.Value == true then
		if Stances.Tourniquet.Value == false then
			Blood.Value = Blood.Value - MLs.Value * BR[6] * step
			MLs.Value = MLs.Value + BR[7] * step

		else
			Blood.Value = Blood.Value - MLs.Value * BR[8] * step
			MLs.Value = MLs.Value + BR[9] * step
		end

		if Stances.skit.Value == true and (BR[3] ~= 0 or not Stances.Tourniquet.Value) then -- starter iv kit
			Blood.Value = Blood.Value - MLs.Value * BR[10] * step
		end	
		MaxBlood = Blood.Value
	end



	if Stances.Tourniquet.Value and Config.TourniquetPainRate ~= 0 then
		Pain.Value = Pain.Value + Config.TourniquetPainRate * step * 60
	end

	if Config.PainKnocksOut and Pain.Value >= Config.KOPain or Config.BloodLossKnocksOut and Blood.Value < Config.KOBlood then
		Caido.Value = true
	end



	if MaxHealth - human.Health > 0 then
		Pain.Value = math.ceil(Pain.Value + (MaxHealth - human.Health) * Config.PainMult)
		--Energia.Value = math.ceil(Energia.Value + (human.Health - MaxHealth)*(5))
		if Bleeding.Value then
			MLs.Value = MLs.Value + (MaxHealth - human.Health) * Config.BloodMult
		end
	end

	-- new bleed to death script block
	if Blood.Value == 0 and Config.BleedToDeath then
		human.Health = 0
		dead.Value = true
	end

	if script.Parent.Parent.Humanoid.Health < MaxHealth -(Config.BleedDamage) then
		Bleeding.Value = true

		if script.Parent.Parent.Humanoid.Health < MaxHealth -(Config.InjuredDamage) then
			Ferido.Value = true
			ChangeBBleeding()
			Bleeding.Value = true
			if script.Parent.Parent.Humanoid.Health < MaxHealth -(Config.KODamage) then
				Caido.Value = true -- knocked out
				Bleeding.Value = true
				ChangeBBleeding()

			end	
		end
	end

	if script.Parent.Parent.Humanoid.Health <= 2 then
		rodeath.Value = true
		human.PlatformStand = true
		human.AutoRotate = false
		Caido.Value = true	
		--cpr.Value = false
		life.Value = false
		Bleeding.Value = true
		ChangeBBleeding()
	end










	if human.Health >= human.MaxHealth and Bleeding.Value == false then
		Blood.Value = Blood.Value + Config.BloodRecoveryRate * step
		Pain.Value = Pain.Value - Config.PainRecoveryRate * step
		MLs.Value = MLs.Value - Config.MLRecoveryRate * step		

	end

	MaxHealth = script.Parent.Parent.Humanoid.Health


	--spawn(function(timer)
	--	if (Blood.Value >= Config.KOBlood or not Config.BloodLossKnocksOut) and (Pain.Value < Config.KOPain or not Config.PainKnocksOut) and Caido.Value == true and debounce == false then
	--		debounce = true
	--		wait(60)
	--		debounce = false
	--	end	
	--end)

	local currhealth = 100



	if life.Value == false or rodeath.Value == true then

		human.PlatformStand = true
		human.AutoRotate = false	
		Caido.Value = true	

		local DyingDamage = math.clamp(MLs.Value/8000, 0.1, 0.14)
		if o2.Value == true then
			DyingDamage = 0.005
			MLs.Value = 0
		end
		human.Health = human.Health - DyingDamage
		if Stances.Tourniquet.Value == false then
			Blood.Value = (Blood.Value - (MLs.Value/90))
			MLs.Value = MLs.Value + 0.025
		else
			Blood.Value = (Blood.Value - (MLs.Value/210))
			MLs.Value = MLs.Value + 0.025
		end
	end






end



