If statement not working if the answer is 0

So basically I have an if statement that checks if the rock i mined is at 0 or < than 0 health but it only works if it’s >0

I’ve printed in the output and it only shows the print when its under 0

if HitsToBreak.Value < 0 then
						print(HitsToBreak.Value)
						warn("destroyed")
						
						RS.Remotes.Event.Break:FireClient(Player, Target.Parent.Name, Reward.Value, HitsToBreak.Value, MaxHealth.Value)
						
						Player:FindFirstChild("Ores")[Target.Parent.Name].Value += Reward.Value

						for i, v in pairs(Target.Parent:GetDescendants()) do
							if v:IsA("BasePart") then
								local Tween = TweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1})
								v.CanCollide = false
								Tween:Play()
							end
						end
						
						local TweenRockModel = TweenService:Create(Target.Parent, TweenInfo.new(0.5), {Transparency = 1})
						Target.Parent.CanCollide = true

						task.wait()


						Target.Parent.Parent = game.ReplicatedStorage
						wait(0.1)
						HitsToBreak.Value = MaxHealth.Value

						for i, v in pairs(Target.Parent:GetDescendants()) do
							if v:IsA("BasePart") and v.Name ~= "Hitbox" then
								v.CanCollide = true
								v.Transparency = 0
							end
						end
						
						Target.Parent.CanCollide = true
						Target.Parent.Transparency = 0


						task.wait(Cooldown)
						Debounce = false
						Table[Player] = nil

						task.wait(RegenTime.Value)
						
						for i, v in pairs(Target.Parent:GetDescendants()) do
							if v:IsA("BasePart") and v.Name ~= "Hitbox" then
								v.CanCollide = true
								v.Transparency = 0
							end
						end

						Target.Parent.CanCollide = true
						Target.Parent.Transparency = 0

						Target.Parent.Parent = game.Workspace.Rocks
					else
						RS.Remotes.Event.Break:FireClient(Player, Target.Parent.Name, Reward.Value, HitsToBreak.Value, MaxHealth.Value)
					end

Haven’t read it all, but you’re only checking if it is less than zero. Replace ‘<’ with ‘<=’

2 Likes

print your HitsToBreak.Value before the if check. (also make it <= instead of just <)

It may be calculating to .0001 or -.000001 so your 0 value might be skewed.

It says 0 and I tried to remove the <= and add it again but still didn’t work

Oh wait it works now, i don’t know what i did but any ways thanks for the help guys

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.