Okay, so basically this is supposed to pick a random Money# from the list and print which one is chosen through a chance which is random. And on line 16 it gives me the error of "Attempt to compare number with 'nil'"

local chance = {
	["Money1"] = 100; -- [Silver] - Common
	["Money2"] = 50; -- [Gold] - Uncommon
	["Money3"] = 15; -- [Diamond] - Rare
};

script.Parent.ClickDetector.MouseClick:connect(function()
-- Choose what Money to spawn based on chance
	local moneyToDo = {
		["Money1"] = false; -- [Silver]
		["Money2"] = false; -- [Gold]
		["Money3"] = false; -- [Diamond]	
	};
	
	for i = 1, 4 do
		if math.random(1,100) < chance["Money"..i] then --"Attempt to compare number with 'nil'"
			moneyToDo["Money"..i] = true;
			if i > 1 then -- If Rarer Currency is spawning then don't spawn a less rare one
				moneyToDo["Money"..i-1] = false;
			end
		end
	end
	
	if moneyToDo.Money1 then
		print("Money 1")
	elseif moneyToDo.Money2 then
		print("Money 2")
	elseif moneyToDo.Money3 then
		print("Money 3")
	end
end)

2 comments

0

Your loop runs from 1 ~ 4 and you only have money up to 3

0

I just saw that wow...