If 0 ignore else continue

Hello, I’m trying to modify a script that adds value to an item depending on if the items value is higher than the stated max value. Basically if MaxValue = 0 then there is no max value but if MaxValue = 20 for example it will only add to Value until Value = 20

I am using Zonix_official Sandbox and i have defined Maxvalue in the itemstats module as

module.MaxValue = 0 -- If 0 not enabled. If value then set max value

I have been able to achieve checking that the value is >= to ORE_MAXVALUE easily but when it is set as 0 it breaks.

ORE:FindFirstChild("Cash").Value >= ORE_MAXVALUE then

How do i disable it If MaxValue = 0?

Hope that makes sense

  1. You can use math.clamp(CashValue, 0, OreMax)
  2. Use greater > than instead of greater and equal to >=
local maxvalue_exmaple = 0
local ORE = game.Player --idk the file
if ORE:FindFirstChild("Cash").Value > maxvalue_exmaple then
print("continue")
else
print("disable")
return
end

idk if this works

Could either do module.MaxValue = 1 or use > instead of >= in the conditional check.

I’m not quite sure how i’m adding this.

The itemhandler module script is in replicated storage with the whole thing looking like this

function module.UPGRADE_ORE(PLOT, UPGRADER, ORE, ORE_ADD, ORE_MULTI, ORE_MAXVALUE, TAG_NAME, LIMIT_USE)
	local PLOT_OWNER = Plrs:FindFirstChild(PLOT.Owner.Value)
	if ORE:FindFirstChild("Cash") then
		local TAG = ORE:FindFirstChild(TAG_NAME)
		if TAG then
			if TAG.Value > LIMIT_USE or ORE.Cash.Value > ORE_MAXVALUE then
				return false
			end
		end
		if TAG == nil then
			TAG = Instance.new("NumberValue", ORE)
			TAG.Name = TAG_NAME
			TAG.Value = 0
		end
		TAG.Value += 1		-- Do this here cause it's best place, don't move it >:C
		if ORE_MULTI > 0 then
			ORE.Cash.Value *= ORE_MULTI
		end
		if ORE_ADD > 0 then
			ORE.Cash.Value += ORE_ADD
		end
		return true
	end
	return false
end

The itemstats modulescript looks like this

local module = {}

module.ItemId = 4
module.TierId = 1
module.Description = "Give ores a nice $1 boost until the ore reaches $30!"
module.ThumbnailId = "rbxassetid://7448167682"
module.Cost = 150
module.CostType = "Cash"
module.ItemType = "MachineTab"
module.TabItem = "Machine"

module.ConveyorSpeed = 8
module.Multiplier = 0
module.Addition = 1
module.DropWorth = 0
module.DropSize = 0
module.DropSpeed = 0

module.MaxValue = 0 -- overall value limit

module.Creators = {"Zonix_Official"}
module.SpecialTags = {
	
}

return module

The main part im looking is in the ItemHandler

if TAG.Value > LIMIT_USE or ORE.Cash.Value > ORE_MAXVALUE then

Obviously the above doesnt work at all if MaxValue = 0, would my script look more like this?

if TAG.Value > LIMIT_USE or ORE.Cash.Value > math.clamp(Ore.Cash.Value, 0, ORE_MAXVALUE)

Thanks for the help

Forgot to mention that when the ore is spawned it always has a cash value on spawn

function module.UPGRADE_ORE(PLOT, UPGRADER, ORE, ORE_ADD, ORE_MULTI, ORE_MAXVALUE, TAG_NAME, LIMIT_USE)
	local PLOT_OWNER = Plrs:FindFirstChild(PLOT.Owner.Value)
	if ORE:FindFirstChild("Cash") then
		local TAG = ORE:FindFirstChild(TAG_NAME)
		if TAG then -- Imma be real I dont know what the hell this is
			if TAG.Value >= LIMIT_USE or ORE.Cash.Value >= ORE_MAXVALUE then
				return false
			end
		else -- Makes a new TAG
			TAG = Instance.new("NumberValue", ORE)
			TAG.Name = TAG_NAME
			TAG.Value = 0
		end
		TAG.Value = math.clamp(Tag.Value + 1, 0, LIMIT_USE) -- Locks it to a max and min
		ORE.Cash.Value = math.clamp(ORE.Cash.Value * ((ORE_MULTI > 0 and ORE_MULTI) or 1) + ((ORE_ADD >= 0 and ORE_ADD) or 0), 0, ORE_MAXVALUE)
		-- Let me simplify what this does:
		-- Math.clamp puts a max and min value to the CashValue
		-- The OreMulti returns 1 if OreMult <= 0 else it returns itself
		-- Same for OreAdd, but it returns 0 if its under 0.
		return true
	end
	return false
end

I’m getting the below results with that. Spawn block with value of 1 then it goes to 0 on touching the upgrade

image

Please put this

print((ORE_MULTI > 0 and ORE_MULTI) or 1)

Under the math.clamps and tell me the results.
Oh yeah if ORE_MAXVALUE is 0 it will result in the part becoming 0, so check if it is by doing:

print(ORE_MAXVALUE)

If the cash value has reached MAXVALUE it should return false. Your code would return true always wouldn’t it? This is the code for the upgrade

local ORIG_COLOR = script.Parent.Upgrade.Color
local RepStorage = game:GetService("ReplicatedStorage")
local ITEM_HANDLER = require(RepStorage.Modules.ItemHandler)
local ITEM_INFO = require(script.Parent.Parent.ItemStats)
local PLOT = script.Parent.Parent.Parent.Parent

script.Parent.Upgrade.Touched:Connect(function(ORE)
	if ORE:FindFirstChild("Cash") then
		local PLOT = script.Parent.Parent.Parent.Parent
		local UPGRADE_ORE = ITEM_HANDLER.UPGRADE_ORE(PLOT, script.Parent.Parent, ORE, ITEM_INFO.Addition, ITEM_INFO.Multiplier, ITEM_INFO.MaxValue, ITEM_INFO.ItemId, 30)
		if UPGRADE_ORE == true then
			
		elseif UPGRADE_ORE == false then
			script.Parent.Upgrade.Color = Color3.fromRGB(99, 99, 99)
			wait(.2)
			script.Parent.Upgrade.Color = ORIG_COLOR
		end
	end
end)

No, this is called if statements in variables, basically it returns a number; its basically like a function, that’s why I have the failsafe or 1.
More on it here:

Please check my previous post.

image

It should then be a ORE_MAXVALUE mistake, as in it’s 0.
You could ORE_MAXVALUE it with:

ORE_MAXVALUE >= 1 and ORE_MAXVALUE or 1

(At the end of the math.clamp)
Another way to fix is is by changing the value of ORE_MAXVALUE to 1+.

I couldn’t wrap my head around the way you suggests, i think im too new to lua to understand it at the moment but i did manage to get it working however.

I used a Boolean to determine if the check is on or not.

module.MaxValueOn = false -- is the value limit on?
module.MaxValue = 3 -- overall value limit
if ORE_MAXVALUEON == true and ORE.Cash.Value >= ORE_MAXVALUE then
				return false

Is there any flaws to doing it this way? Or is it acceptable?