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

Make it so if your underwater riding a boat you run out of oxygen?

Asked by 1 year ago

So if your boat is flipped upside down make it so you lose oxygen until you exit the seat and swim up to the surface

local bar = script.Parent.BarBG.Bar
local oxygenLabel = script.Parent.BarBG.OxygenAmount

local maxOxygen = 100
local currentOxygen = maxOxygen

local timePerLoss = 0.3
local chairwater = false
local isSwimming = false

local char = game.Players.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")


hum.StateChanged:Connect(function(oldState, newState)


    if newState == Enum.HumanoidStateType.Swimming then

        isSwimming = true
        script.Parent.Enabled = true

    elseif chairwater == false then
        isSwimming = false
    end
end)
char.Torso.Touched:Connect(function(hit)
    if hit:IsA("Water") and hum.Sit == true then
        chairwater = true
        isSwimming = true
    else
        chairwater = false
    end
end)


while wait(timePerLoss) do


    if isSwimming then

        currentOxygen = math.clamp(currentOxygen - 1, 0, maxOxygen)

    else
        currentOxygen = math.clamp(currentOxygen + 1, 0, maxOxygen)
    end


    if currentOxygen < 1 then

        hum.Health = 0
    end


    local barScale = currentOxygen / maxOxygen
    bar:TweenSize(UDim2.new(barScale, 0, 1, 0), "InOut", "Linear", timePerLoss)

    oxygenLabel.Text = currentOxygen .. " / " .. maxOxygen
    if currentOxygen == maxOxygen then
        script.Parent.Enabled = false
    end
end
0
This isn't a question? iiDev_Hunt3r 64 — 1y
0
it is a question SpriteGamerHD 47 — 1y
0
also if the question dosent make sense basically if your boat tips upside down it dosent take away oxygen until you exit the chair SpriteGamerHD 47 — 1y
0
This is more of a script request than a question ScriptGuider 5640 — 1y
0
line 27 to line 34 SpriteGamerHD 47 — 1y

Answer this question