Hey guys, so I've got this script that I've been working on for a while now and I'm very close to done with it, but there's one issue, it won't take damage or print when the value drops below zero. Here is the script,
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Player.Character:WaitForChild("Humanoid") local air = script.Parent local gui = script.Parent.Parent.Parent.PlayerGui if Character:FindFirstChild("SmallAir") then -- if u have small tank then air start is 30 air.Value = 40 end wait(8) while wait(1) do -- diminish air every second/do damage at 0 if Character:FindFirstChild("SmallAir") then air.Value = air.Value - 1 print("Run Successfully") if air.Value >= 0 then print(air.Value.." air remaining.") gui.AirCanStat.HeadText.Label.Text = air.Value.."/40" if air.Value == 40 then gui.AirCanStat.BlueBody:TweenPosition(UDim2.new(0.023, 0,0.641, 0), 'Out', 'Linear', 1, false) gui.AirCanStat.BlueBody.BackgroundColor = BrickColor.new("Cyan") end if air.Value == 30 then gui.AirCanStat.BlueBody:TweenPosition(UDim2.new(0.023, 0,0.727, 0), 'Out', 'Linear', 1, false) gui.AirCanStat.BlueBody.BackgroundColor = BrickColor.new("Cyan") end if air.Value == 20 then gui.AirCanStat.BlueBody:TweenPosition(UDim2.new(0.023, 0,0.811, 0), 'Out', 'Linear', 1, false) gui.AirCanStat.BlueBody.BackgroundColor = BrickColor.new("Cyan") end if air.Value == 10 then gui.AirCanStat.BlueBody:TweenPosition(UDim2.new(0.023, 0,0.892, 0), 'Out', 'Linear', 1, false) gui.AirCanStat.BlueBody.BackgroundColor = BrickColor.new("Really red") end if air.Value == 0 then gui.AirCanStat.BlueBody:TweenPosition(UDim2.new(0.023, 0,0.988, 0), 'Out', 'Linear', 1, false) end if air.Value <= 0 then print("No air remaining!") Humanoid:TakeDamage(10) end end end end
With this script, it works one time (when the value drops to exactly zero) but if I remove the equal sign and make it just if air.Value < 0 then but when I do this, nothing happens, no damage taken and no print, there is also no error, which is why I'm confused
Thanks!
So the problem was that it kept looping back to the if air.Value >= 1 then, so it never got to -1