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
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
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
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
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:
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?