Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Oxygen script works, but not at the right time. Help me fix it? [STILL UNSOLVED]

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
0
Does it deplete when when you're outside too, or does it have the effects of being inside normally? Spongocardo 1991 — 9y
0
It depletes when you're inside, which it's not supposed to. TheRings0fSaturn 28 — 9y
0
Also, I was wanting it to play a sound when you're outside. I'll upload the sound soon, when I get the ROBUX. I just need the script stuff. lol TheRings0fSaturn 28 — 9y
0
So it depletes when you're both inside and outside? Spongocardo 1991 — 9y
View all comments (3 more)
0
Yes. TheRings0fSaturn 28 — 9y
0
This script can be made significantly simpler and cleaner. BlueTaslem 18071 — 9y
0
I am not the greatest programmer, but I would probably just use a touchedConnect script on a part that covers the outside. OBenjOne 190 — 6y

Answer this question