Hello, everyone. I am currently trying to convert this script so it will only work if you're outside. It also will kill you instantly. Also, by killing you instantly, I mean when your air is out. And my game wont have water. Also, when you're outside, it plays a sound. I'll upload the sound eventually, just put in a breathing sound ID.
local player = script.Parent.Parent.Parent.Parent
repeat wait() until player.Character
local lastHealth = 100
local lastHealth2 = 100
local maxWidth = 0.96
local humanoid = script.Air
function UpdateGUI(health)
tray = script.Parent
local width = (health / humanoid.MaxValue) * maxWidth
local height = 0.83
local lastX = tray.bar.Position.X.Scale
local x = 0.019 + (maxWidth - width)
local y = 0.1
tray.bar.Position = UDim2.new(x,0,y, 0)
tray.bar.Size = UDim2.new(width, 0, height, 0)
-- If more than 1/4 health, bar = green. Else, bar = red.
if( (health / humanoid.MaxValue) > 0.25 ) then
tray.barRed.Size = UDim2.new(0, 0, 0, 0)
else
tray.barRed.Position = tray.bar.Position
tray.barRed.Size = tray.bar.Size
tray.bar.Size = UDim2.new(0, 0, 0, 0)
end
if ( (lastHealth - health) > (humanoid.MaxValue / 10) ) then
lastHealth = health
if humanoid.Value ~= humanoid.MaxValue then
delay(0,function()
AnimateBars(x, y, lastX, height)
end)
end
else
lastHealth = health
end
end
function HealthChanged()
health = humanoid.Value
UpdateGUI(health)
if ( (lastHealth2 - health) > (humanoid.MaxValue / 10) ) then
lastHealth2 = health
else
lastHealth2 = health
end
end
function AnimateBars(x, y, lastX, height)
tray = script.Parent
local width = math.abs(x - lastX)
if( x > lastX ) then
x = lastX
end
tray.bar2.Position = UDim2.new(x,0, y, 0)
tray.bar2.Size = UDim2.new(width, 0, height, 0)
tray.bar2.BackgroundTransparency = 0
local GBchannels = 1
local j = 0.2
local i_total = 30
for i=1,i_total do
-- Increment Values
if (GBchannels < 0.2) then
j = -j
end
GBchannels = GBchannels + j
if (i > (i_total - 10)) then
tray.bar2.BackgroundTransparency = tray.bar2.BackgroundTransparency + 0.1
end
tray.bar2.BackgroundColor3 = Color3.new(1, GBchannels, GBchannels)
wait(0.02)
end
end
humanoid.Changed:connect(HealthChanged)
while wait() do
local headLoc = game.Workspace.Terrain:WorldToCell(player.Character.Head.Position)
-- print(headLoc)
local hasAnyWater = game.Workspace.Terrain:GetWaterCell(headLoc.x, headLoc.y, headLoc.z)
-- print(hasAnyWater)
if player.Character.Humanoid.Health ~= 0 then
if hasAnyWater then
if humanoid.Value > humanoid.MinValue then
script.Parent.Visible = true
humanoid.Value = humanoid.Value-0.1
elseif humanoid.Value <= humanoid.MinValue then
player.Character.Humanoid:TakeDamage(0.2)
end
else
if humanoid.Value < humanoid.MaxValue then
humanoid.Value = humanoid.Value+5
else
script.Parent.Visible = false
end
end
end
end
