Make it so if your underwater riding a boat you run out of oxygen?
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
01 | local bar = script.Parent.BarBG.Bar |
02 | local oxygenLabel = script.Parent.BarBG.OxygenAmount |
05 | local currentOxygen = maxOxygen |
07 | local timePerLoss = 0.3 |
08 | local chairwater = false |
09 | local isSwimming = false |
11 | local char = game.Players.LocalPlayer.Character |
12 | local hum = char:WaitForChild( "Humanoid" ) |
15 | hum.StateChanged:Connect( function (oldState, newState) |
18 | if newState = = Enum.HumanoidStateType.Swimming then |
21 | script.Parent.Enabled = true |
23 | elseif chairwater = = false then |
27 | char.Torso.Touched:Connect( function (hit) |
28 | if hit:IsA( "Water" ) and hum.Sit = = true then |
37 | while wait(timePerLoss) do |
42 | currentOxygen = math.clamp(currentOxygen - 1 , 0 , maxOxygen) |
45 | currentOxygen = math.clamp(currentOxygen + 1 , 0 , maxOxygen) |
49 | if currentOxygen < 1 then |
55 | local barScale = currentOxygen / maxOxygen |
56 | bar:TweenSize(UDim 2. new(barScale, 0 , 1 , 0 ), "InOut" , "Linear" , timePerLoss) |
58 | oxygenLabel.Text = currentOxygen .. " / " .. maxOxygen |
59 | if currentOxygen = = maxOxygen then |
60 | script.Parent.Enabled = false |