Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I got this error: attempt to perform arithmetic on upvalue 'RarityItems'(a table value) help?

local Raritytimes = {
	["Common"] = 80,
	["Uncommon"] = 15,
	["Rare"] = 5,
}

local CrateInude = false

local function opencrate(Chance)
	if CrateInude == false then
		CrateInude = true
		local items = {}
		local frametimes = math.random(30,32)
		local rewardbutton
		for i,v in pairs(game.ReplicatedStorage.Items:GetChildren()) do
			local rarnumber = Raritytimes[v.Rarity.Value] or 1
			local mathmatical = math.max(Raritytimes+Chance)
			for i = 1,mathmatical do
				table.insert(items,v)
			end
		end
		
		math.randomseed(tick())		
		
		for i = 1,frametimes+5 do
			local item = items[math.random(#items)]
			local newsapme = script.Parent.Unboxing.SampleItem:Clone()
			newsapme.Visible =true
			newsapme.Parent = script.Parent.Unboxing.inner
			newsapme.Icon.Image = item.Image.Value
			newsapme.ItemName.Text = item.Name
			newsapme.Position = UDim2.new(0,100*(i-1),0,0)
			if i == frametimes then
				rewardbutton = newsapme
			end
		end
		for num = 1,(rewardbutton.Position.X.Offset - (255+math.random(-40,40)))/15 do
			for i,v in pairs(script.Parent.Unboxing.inner:GetChildren()) do
				v.Position = UDim2.new(0,v.Position.Offset-15,0,0)
				if v.Position.X.Offset <= -150 then
					v:Destroy()
				end
			end
			wait(0.01 * 1.05 ^ (num-105)/2)
			script.Tick:Play()
		end
	end
end

opencrate(0)

The error is: 12:05:27.690 - Players.shootthegame.PlayerGui.BasicCrate.LocalScript:17: attempt to perform arithmetic on upvalue 'Raritytimes' (a table value)

(the error is in line line 17)

Can anyone help me fix the problem?

1 answer

You are trying to pass a table to math.max,something you cannot do. Your two options to fix this are:

1)Get the length of the table. This is done via the # operator before the table name. In your case it would be 3.

2)Get the value within the table. So if you want the value for "Common", you would do:Raritytimes["Common"] and that would become 80.

This discussion is preserved as it was. New answers, comments, and votes are closed.