If a player is touching the water part, a blue bar GUI will appear on their screen, showing their air. If they are in for too long, it will start to deal damage until they get out of the water. However, it doesn't show the air bar decreasing, and it also doesn't stop dealing damage if they get out.
local air = script.Parent
local hitbox = game.Workspace.WaterHitbox
local airBarSize = air.CurrentAir.Size.X.Offset
air.Enabled = false
hitbox.Touched:connect(function(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then --if a humanoid exists
air.Enabled = true --show air bar
repeat
wait (0.01)
airBarSize = airBarSize - 2
until airBarSize == 0
repeat
humanoid.Health = humanoid.Health - 1
wait()
until not airBarSize == 0
end
end)
hitbox.TouchEnded:connect(function(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
airBarSize = 544
air.Enabled = false
end
end)

1 comment
Thanks for helping! Shame I can only accept 1 answer.