Anyways, this is my script. I'm making a DOOM game, and if you go outside of the building, you start suffocate, in other words, you have limited Oxygen. But, the only thing is, it WORKS, but....it works when it's not supposed to. In other words, your oxygen level drops even when you're inside. I was wondering if someone could fix this. (Problem starts on line 82.) Also, this is a heavily modified under water script.
Here is the video to what I am trying to recreate (in terms of the Oxygen GUI.) https://www.youtube.com/watch?v=ZFeSDs5hUG4#t=530
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 function findHighestBrickInPlayer(char) local brick = nil function check(part) if part.className == "Part" or part.className == "WedgePart" then if brick == nil or part.CFrame.y > brick.CFrame.y then brick = part end elseif part.className == "Hat" or part.className == "Model" then for i,child in pairs(part:getChildren()) do check(child) end end end check(char) return brick end function isExposed(brick) local testray = Ray.new(brick.Position, Vector3.new(0,999,0)) local part, pos = workspace:findPartOnRay(testray, brick) if part == nil then return true end return false end if player.Character.Humanoid.Health ~= 0 then if isExposed 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(100) end else if humanoid.Value < humanoid.MaxValue then humanoid.Value = humanoid.Value+5 else script.Parent.Visible = false end end end end