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

5 comments

0

This isn't a question?

0

it is a question

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

0

This is more of a script request than a question

0

line 27 to line 34