--print(Valor)

if Valor == true then
	if Correndo.Value == true then
		ChangeStance = true
		Correndo.Value = false
		Stand()
		Stances = 0
	end
	if Stances == 0 then
		Stand()
	end

	TS:Create(Poses.Levantado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(150,0,0)} ):Play()
	TS:Create(Poses.Agaixado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(150,0,0)} ):Play()
	TS:Create(Poses.Deitado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(150,0,0)} ):Play()

	--Poses.Levantado.ImageColor3 = Color3.fromRGB(100,0,0)
	--Poses.Agaixado.ImageColor3 = Color3.fromRGB(100,0,0)
	--Poses.Deitado.ImageColor3 = Color3.fromRGB(100,0,0)
	--Main.Status.Barra.Stamina.BackgroundColor3 = Color3.fromRGB(170,0,0)
else
	if Stances == 0 then
		Stand()
	end
	
	TS:Create(Poses.Levantado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(255,255,255)} ):Play()
	TS:Create(Poses.Agaixado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(255,255,255)} ):Play()
	TS:Create(Poses.Deitado, TweenInfo.new(5), {ImageColor3 =  Color3.fromRGB(255,255,255)} ):Play()

	--Poses.Levantado.ImageColor3 = Color3.fromRGB(0,0,0)
	--Poses.Agaixado.ImageColor3 = Color3.fromRGB(0,0,0)
	--Poses.Deitado.ImageColor3 = Color3.fromRGB(0,0,0)
	--Main.Status.Barra.Stamina.BackgroundColor3 = Color3.fromRGB(125,125,125)
end
end)

local BleedTween = TS:Create(Main.Poses.Bleeding, TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,-1,true), {ImageColor3 =  Color3.fromRGB(150, 0, 0)} )

Sangrando.Changed:Connect(function(Valor)
if Valor == true then
	Main.Poses.Bleeding.ImageColor3 = Color3.fromRGB(255,255,255)
	Main.Poses.Bleeding.Visible = true
	BleedTween:Play()
else
	Main.Poses.Bleeding.Visible = false
	BleedTween:Cancel()
end
end)

Caido.Changed:Connect(function(Valor)
if Valor == true then
		if Stances ~= 0 then

			Poses.Levantado.Visible = true
			Poses.Agaixado.Visible = false
			Poses.Deitado.Visible = false
			Poses.Esg_Right.Visible = false
			Poses.Esg_Left.Visible = false
			CameraX = 0
			CameraY = 1
			Stances = 0
			Correndo.Value = false
			Steady = false
			Stand()
		end
	
end
end)


local a = Main.Vest.TextBox
local b = Main.Helm.TextBox
local Ener = Main.Poses.Energy

function Vest()
	a.Text = math.ceil(Protecao.VestVida.Value)
	a.Parent.ImageColor3 = Color3.fromRGB(255,0,0)
	TS:Create(a.Parent, TweenInfo.new(2), {ImageColor3 =  Color3.fromRGB(255, 255, 255)} ):Play()
	if Protecao.VestVida.Value <= 0 then
		a.Parent.Visible = false
	else
		a.Parent.Visible = true
	end
end

function Helmet()
	b.Text = math.ceil(Protecao.HelmetVida.Value)
	b.Parent.ImageColor3 = Color3.fromRGB(255,0,0)
	TS:Create(b.Parent, TweenInfo.new(2), {ImageColor3 =  Color3.fromRGB(255, 255, 255)} ):Play()

	if Protecao.HelmetVida.Value <= 0 then
		b.Parent.Visible = false
	else
		b.Parent.Visible = true
	end
end

function Stamina()
if ServerConfig.EnableStamina then
	if saude.Variaveis.Stamina.Value <= (saude.Variaveis.Stamina.MaxValue/2) then
		Ener.ImageColor3 = Color3.new(1,saude.Variaveis.Stamina.Value/(saude.Variaveis.Stamina.MaxValue/2),saude.Variaveis.Stamina.Value/saude.Variaveis.Stamina.MaxValue)
		Ener.Visible = true
	elseif saude.Variaveis.Stamina.Value < saude.Variaveis.Stamina.MaxValue then
		Ener.ImageColor3 = Color3.new(1,1,saude.Variaveis.Stamina.Value/saude.Variaveis.Stamina.MaxValue)
		Ener.Visible = true
	elseif saude.Variaveis.Stamina.Value >= saude.Variaveis.Stamina.MaxValue then
		Ener.Visible = false
	end
else
	saude.Variaveis.Stamina.Value = saude.Variaveis.Stamina.MaxValue
	Ener.Visible = false
end
end

Vest()
Helmet()
Stamina()

Protecao.VestVida.Changed:Connect(Vest)
Protecao.HelmetVida.Changed:Connect(Helmet)
saude.Variaveis.Stamina.Changed:Connect(Stamina)

Character.Humanoid.Changed:connect(function(Property)
	if ServerConfig.AntiBunnyHop then
		if Property == "Jump" and Character.Humanoid.Sit == true and Character.Humanoid.SeatPart ~= nil then
		Character.Humanoid.Sit = false
		elseif Property == "Jump" and Character.Humanoid.Sit == false then
			if JumpDelay then
				Character.Humanoid.Jump = false
				return false
			end
			JumpDelay = true
			delay(0, function()
				wait(ServerConfig.JumpCoolDown)
				JumpDelay = false
			end)
		end
	end
end)



local uis = game:GetService('UserInputService')
local Evt = Engine:WaitForChild("Eventos")
local placeEvent = Evt.Rappel:WaitForChild('PlaceEvent')
local ropeEvent = Evt.Rappel:WaitForChild('RopeEvent')
local cutEvent = Evt.Rappel:WaitForChild('CutEvent')

uis.InputBegan:connect(function(input,chat)
	if not chat and Rappeling.Value == true then
		if input.KeyCode == Enum.KeyCode.C then
			ropeEvent:FireServer('Up',true)
		end;
		
		if input.KeyCode == Enum.KeyCode.X then
			ropeEvent:FireServer('Down',true)
		end;
	end
end)

uis.InputEnded:connect(function(input,chat)
	if not chat and Rappeling.Value == true then		
		if input.KeyCode == Enum.KeyCode.C then
			ropeEvent:FireServer('Up',false)
		end;
		
		if input.KeyCode == Enum.KeyCode.X then
			ropeEvent:FireServer('Down',false)
		end;
	end
end)



function L_150_.Update()

local L_174_ = CFrame.new()
L_153_.cornerPeek.t = L_153_.peekFactor * Virar
local L_326_ = CFrame.fromAxisAngle(Vector3.new(0, 0, 1), L_153_.cornerPeek.p) -- SOLUTION TO 3RD PERSON --> CFrame.new(10,0,0) * CFrame.fromAxisAngle(Vector3.new(0,0,1), this.cornerPeek.p)
Camera.CFrame = Camera.CFrame * L_326_ * L_174_
if saude.Variaveis.Stamina.Value <= (saude.Variaveis.Stamina.MaxValue/2) then
local StaminaX = (1 - (saude.Variaveis.Stamina.Value)/(saude.Variaveis.Stamina.MaxValue/2))/20
Camera.CoordinateFrame = Camera.CoordinateFrame * CFrame.Angles( math.rad( StaminaX * math.sin( tick() * 3.5 )) , math.rad( StaminaX * math.sin( tick() * 1 )), 0)
end
end


local Nadando = false

function onStateChanged(_,state)
	--print(state)
	if state == Enum.HumanoidStateType.Swimming then
		Nadando = true
	else
		Nadando = false
	end
end

maxAir = 100
air = maxAir

lastHealth = 100
lastHealth2 = 100
maxWidth = 0.96

Humanoid.StateChanged:connect(onStateChanged)
game:GetService("RunService"):BindToRenderStep("Camera Update", 200, L_150_.Update)

while wait() do
	if ServerConfig.CanDrown then
		local headLoc = game.Workspace.Terrain:WorldToCell(player.Character.Head.Position)
		local hasAnyWater = game.Workspace.Terrain:GetWaterCell(headLoc.x, headLoc.y, headLoc.z)
		if player.Character.Humanoid.Health ~= 0 then
			if hasAnyWater then
				if air > 0 then
					air = air-0.15
				elseif air <= 0 then
					air = 0
					Evt.Afogar:FireServer()
				end
			else
				if air < maxAir then
					air = air + .5
				end
			end
		end
	
		if air <= 50 then
			script.Parent.Frame.Oxygen.ImageColor3 = Color3.new(1,air/50,air/100)
			script.Parent.Frame.Oxygen.Visible = true
		elseif air < maxAir then
			script.Parent.Frame.Oxygen.ImageColor3 = Color3.new(1,1,air/100)
			script.Parent.Frame.Oxygen.Visible = true
		elseif air >= maxAir then
			script.Parent.Frame.Oxygen.Visible = false
		end
		script.Parent.Efeitos.Oxigen.ImageTransparency = air/100
		if air <= 25 then
			script.Parent.Efeitos.Oxigen.BackgroundTransparency = air/25
		end
	end
	if ServerConfig.EnableStamina then
		if Correndo.Value == true and Velocidade > 0 then
			saude.Variaveis.Stamina.Value = saude.Variaveis.Stamina.Value - ServerConfig.RunValue
		elseif Stances == 0 and (Correndo.Value == false or Velocidade <= 0) then
			saude.Variaveis.Stamina.Value = saude.Variaveis.Stamina.Value + ServerConfig.StandRecover
		elseif Stances == 1 and (Correndo.Value == false or Velocidade <= 0) then
			saude.Variaveis.Stamina.Value = saude.Variaveis.Stamina.Value + ServerConfig.CrouchRecover
		elseif Stances == 2 and (Correndo.Value == false or Velocidade <= 0) then
			saude.Variaveis.Stamina.Value = saude.Variaveis.Stamina.Value + ServerConfig.ProneRecover
		end
	end
end
