--end


function UpdateGUI(health)
	local pgui = game.Players:GetPlayerFromCharacter(humanoid.Parent).PlayerGui
	local tray = pgui.HealthGUI.Tray
	
	tray.HealthBar.Size = UDim2.new(0.2, 0, 0.8 * (health / humanoid.MaxHealth), 0) 
	tray.HealthBar.Position = UDim2.new(0.4, 0, 0.8 * (1-  (health / humanoid.MaxHealth)) , 0) 
	if script.Parent.Humanoid.Health <= 30 then
		tray.HealthBar.BackgroundColor3 = Color3.new(255/255, 0/255, 0/255)
		print("red")
		tray.Color.Value = "Red"
	elseif script.Parent.Humanoid.Health <= 70 then
		tray.HealthBar.BackgroundColor3 = Color3.new(255/255, 255/255, 0/255)
		print("yellow")
		tray.Color.Value = "Yellow"
	elseif script.Parent.Humanoid.Health > 70 then
		tray.HealthBar.BackgroundColor3 = Color3.new(0/255, 255/255, 0/255)
		print("green")
		tray.Color.Value = "Green"
	end
	if script.Parent.Humanoid.Health == 0 then
		print("dead")
		tray.Color.Value = "Dead"
	end
end


function HealthChanged(health)
	UpdateGUI(health)
end

