So I am making a pickaxe for my survival game, whenever you hit the piece of stone with a pickaxe it will make a value named “Hits” go down by one, then an if statement is stated saying if the value is 0 it checks for the type value and goes with that info.
local tool = script.Parent.Parent
local axeDet = script.Parent
local debounce = false
tool.Equipped:Connect(function()
axeDet.Touched:Connect(function(hit)
if hit.ClassName == "Part" and hit.Name == "Stone" or hit.Name == "Ore" then
print("it was stone")
if debounce == false then
print("good to go")
local hits = hit.Parent.Hits
if hits then
hits.Value = hits.Value - 1
print("hit down")
if hits.Value == 0 then
local typee = hit.Parent.Type
local humanoid = tool.Parent.Humanoid
local plr = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if typee.Value == "Stone" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.stoneCount.Value = plr.hiddenStats.stoneCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Steel" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.steelCount.Value = plr.hiddenStats.steelCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Gold" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.goldCount.Value = plr.hiddenStats.goldCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Coal" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.coalCount.Value = plr.hiddenStats.coalCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
end
end
end
end
else
print("not enough hits")
return
end
debounce = true
wait(3)
debounce = false
end)
end)
It just keeps going into the negatives, and does not return an error, what do I do?
The problem is that he is decreasing the hits value outside of a if statement that checks for the value being not less than one, so the number will go up regardless of the current value. That’s why he needs the if statement I recommended.
This is what I put for it and it says on line #14 it is comparing a number and string?
local tool = script.Parent.Parent
local axeDet = script.Parent
local debounce = false
tool.Equipped:Connect(function()
axeDet.Touched:Connect(function(hit)
if hit.ClassName == "Part" and hit.Name == "Stone" or hit.Name == "Ore" then
print("it was stone")
if debounce == false then
print("good to go")
local hits = hit.Parent.Hits
if hits then
if hits.Value > 0 then
hits.Value -= 1
else
local typee = hit.Parent.Type
local humanoid = tool.Parent.Humanoid
local plr = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if typee.Value == "Stone" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.stoneCount.Value = plr.hiddenStats.stoneCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Steel" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.steelCount.Value = plr.hiddenStats.steelCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Gold" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.goldCount.Value = plr.hiddenStats.goldCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
elseif typee.Value == "Coal" then
plr.hiddenStats.hasStone.Value = true
plr.hiddenStats.coalCount.Value = plr.hiddenStats.coalCount.Value + 1
hit.Parent:Destroy()
print("destroyed")
end
end
end
end
end
debounce = true
wait(3)
debounce = false
end)
end)