"Attempt to compare number < nil" Error

So I am trying to work on my script and it says “attempt to compare number < nil”. Do you mind helping? (Sorry, I am terrible at explaining things :frowning: ).

"Main.Frame.Confirm.MouseButton1Click:Connect(function()
if _G.PlayerData.Candy > 100 then
game.ReplicatedStorage.HW2022.BuyBox:FireServer(tonumber(100))
GameFrame.Shop.Visible = false;
Main.Visible = false
_G.Process(“Unboxing”);

	local StartTime = time();
	local OpenedItem = game.ReplicatedStorage.Remotes.Shop.OpenCrate:InvokeServer("HalloweenBox");
	wait( 0.75-(time()-StartTime));
	--InventoryFrame.Overlay.Visible = false;
	if OpenedItem then
		OpenCrate("HalloweenBox",OpenedItem);
	end;
else
	Main.Visible = false
	_G.GetCredits()
end

end)"

1 Like

I suppose the line where it errors is if _G.PlayerData.Candy > 100 then? If so, you can try inserting this code on top to check if it’s actually a number.

if typeof(_G.PlayerData.Candy) ~= "number" then
    print("Candy value is not a number:", typeof(_G.PlayerData.Candy))
    return
end
1 Like

Sadly, your solution didn’t work. Thanks for taking time and trying to help though! I ended up figuring it out myself.

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