hello, I have a problem and I can’t find a solution, I have an oxygen Gui bar when you are in the water you lose oxygen, however in my game I have the possibility of Ragdoll with F, and when I do it in water, the oxygen bar regenerates it even though it shouldn’t.
Here is the local script in the Gui:
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