If anyone can help i'd be very grateful. :)
local raritys = { Common = 5, Uncommon = 3, Rare = 1, Legendary = 0.2 } local crateInUse = true local function openCrate(chance) if crateInUse == true then local items = {} local result local frametimes = math.random(20,30) for _,Item in pairs(game.ReplicatedStorage.Items:GetChildren()) do local rarNumber = raritys(Item.Rarity.Value) local times = math.max(rarNumber/chance) end math.randomseed(tick()) for num = 1,frametimes+5 do local item = items[math.random(#items)] local newicon = script.Parent.Unboxing.Inner.Icon:Clone() newicon.Visible = true newicon.Parent = script.Parent.Unboxing.Inner newicon.Image = item.ImageID.Value newicon.Position = UDim2.new(0,100*(num-1),0,0) if num == frametimes then result = item crateInUse = false end end end end script.Parent.TextButton.MouseButton1Click:Connect(openCrate(2))
When you have a table, you should index it using []
s. When you have a function, you should call it using ()
.
abnotaddable is correct; the fix is to have local rarNumber = raritys[Item.Rarity.Value]
on line 15.
Also, only use math.randomseed once at the top of the script and use up the first math.random()
without using its value: math.randomseed(tick()); math.random()
. The first random number is rarely different for mildly different seeds.