Whenenver I'm in the part the air value will go above 100 and sometimes at -1 or -2. Also when the value is at 0 the player will not get hurt. What needs to be fixed?
Underwater = script.Parent
Underwater.Touched:Connect(function(hit)
if hit.Parent.ClassName == 'Model' and hit.Parent:FindFirstChild('Humanoid') and not hit.Parent:FindFirstChild('KillerTag') then
print("Head in water")
local character = hit.Parent
Air = character:FindFirstChild("Air")
local Humanoid = character:FindFirstChild("Humanoid")
if hit.Name == "Head" then
while Air.Value > -1 do
wait(1)
Air.Value = Air.Value - 1
while Air.Value <= 0 do
Humanoid.Health = Humanoid.Health - 10
wait(1)
end
end
end
end
end)
Underwater.TouchEnded:Connect(function(hit)
if hit.Parent.ClassName == 'Model' and hit.Parent:FindFirstChild('Humanoid') and not hit.Parent:FindFirstChild('KillerTag') then
local character = hit.Parent
Air = character:FindFirstChild("Air")
local Humanoid = character:FindFirstChild("Humanoid")
while Air.Value < 101 do
wait(1)
Air.Value = Air.Value + 1
end
end
end)
