Value Unknowingly Becoming Blank

I have a value that’s suppose to be equal to 20 which I did on my leaderstats script:

	local RItemMax = Instance.new("IntValue")
	RItemMax.Name = "RItemMax"
	RItemMax.Parent = Values
	RItemMax.Value = 20

For some reason this script

local Cash = game.Players.LocalPlayer.Values.Cash
local Item = game.Players.LocalPlayer.Values.Paper
local MaxSold = game.Players.LocalPlayer.Values.RItemMax
local TimeWait = game.Players.LocalPlayer.Values.RItemTime
local CashName = Cash.Name
local SellingFor = 5
local N2Abbreviate = require(game:GetService("ReplicatedStorage").N2Abbreviate_Module)


while true do
	wait(TimeWait.Value)
	if Item.Value == 0 then
		wait(40)
	end
	if Item.Value > 0 then
		if Item.Value >= MaxSold.Value then
			print(MaxSold.Value)
			local NumberSold = math.random(1,MaxSold.Value)
			RemoteEvent:FireServer(Item,NumberSold,CashName,SellingFor)
			script.Parent.LastSold.Text = "Last Sold ".. NumberSold.." Sheets of Paper!"
			script.Parent.LastSoldAmount.Text = "+$"..N2Abbreviate.Convert(NumberSold*SellingFor,"Advanced")	
	elseif Item.Value < MaxSold.Value then
		local NumberSold = math.random(1,Item.Value)
		RemoteEvent:FireServer(Item,NumberSold,CashName,SellingFor)
		script.Parent.LastSold.Text = "Last Sold ".. NumberSold.." Sheets of Paper!"
			script.Parent.LastSoldAmount.Text = "+$"..N2Abbreviate.Convert(NumberSold*SellingFor,"Advanced")
			end
	   end	
	end	

Prints that RItemMax is Blank and gives an error

Does it print the Value? Can you show that please?

are you applying the leaderstats correctly?

2 Likes

That means that Item.Value is smaller than 1. Make sure the value isn’t smaller than one or the random interval is empty.

An empty interval for math.random just means the first number is smaller than the second number.

1 Like

If you look at the line above the error that was the print.
It came out empty

In this line right here I check for that

No, I’m referring to:
elseif Item.Value < MaxSold.Value then.

1 Like

That line that I was referring too here

Is before the elseif making it impossible for the ItemValue to be 0.

Unless I messed that line up.

Regardless of that in my testing I made sure the value was over 1, making it 33 which is also over the MaxValue.

When I print the MaxValue in the leaderstats script it says the value is 20 but when I do it here it says the value is nil.

Does it print the other values? As in Cash.Value?

1 Like

Yes I just updated it to print those and it prints them just fine.

No because if Item.Value is 0 and Item.Value is less than MaxSold.Value then the elseif would still run causing an issue with math.random(1,0) where Item.Value would be 0.

1 Like

i’d put a bunch of prints to debug the code, it could be possible that your client script initializes way faster than the server script can set the value to 20, it could be reading it weirdly, etc.

1 Like

How would I fix that then?
Getting rid of the else if?