My GUI is an air meter. When entering a giant no-cancollide part, a giant air bar frame shows up and goes to the left. When the blue part of it reaches the end, the player takes damage over time. If you get out, your air instantly refills and disappears. However, when the player is mid-drowning and you get out, you still take damage, and if you get back in the air still shows as 0. I can't UDim2 because TweenSize will not work anymore.

So, I need help with stopping the player from taking damage if they get out, and refilling the air meter if the player goes back in by somehow ending the TweenSize operation mid-way. Perhaps break?

local air = script.Parent
local hitbox = game.Workspace.WaterHitbox
local airBar = air.CurrentAir
local drowning = false
local touching = false
air.Enabled = false

hitbox.Touched:connect(function(part)
	local touching = true
	local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then	--if a humanoid exists
		air.Enabled = true --show air bar
		airBar:TweenSize(UDim2.new(0, 0, 0, 70), "Out", "Quad", 10)
		if airBar.Size.X.Offset == 0 then
			drowning = true
			repeat
				humanoid.Health = humanoid.Health - 0.5
				wait(0.25)
			until drowning == false and touching == false
		end		
	end 
end)

hitbox.TouchEnded:connect(function(part)
	touching = false
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	drowning = false
	if (humanoid ~= nil) then
		if not airBar.Size == "{0, 544},{0, 70}" then
			airBar:TweenSize(UDim2.new(0, 544, 0, 70), "Out", "Quad", 3)
			air.Enabled = true
		else
			air.Enabled = false
		end
	end
end)

2 comments

0

Error on line 11, and 28. No brackets! Error on line 29 as well.

0

Still no answer?