Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bar = script.Parent.BarBG.Bar
- local oxygenLabel = script.Parent.BarBG.OxygenAmount
- local maxOxygen = 100
- local currentOxygen = maxOxygen
- local timePerLoss = 0.3
- 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
- else
- isSwimming = 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
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement