Hello,

I'm making crate drops in my game and want to have a certain percentage chance that the crate will be common, uncommon, rare, or legendary. For some reason only the common and uncommon work. It ignores the rare and legendary.

function crate(player)
local cratetype = math.random(1, 100)
print(cratetype)
if cratetype <= 50 then
	local craterarity = "Common"
	local commonitem = math.random(1, 2)
	-- Speed Knife
	if commonitem == 1 then
		local mydata = playerdata[player.userId]
		mydata.speedknife = mydata.speedknife + 1
		local speedknifevalue = player:WaitForChild("Speed Knife")
		if speedknifevalue ~= nil then
			speedknifevalue.Value = mydata.speedknife
			event:FireClient(player , "Crate", "Common", "Speed Knife")
		end
		-- Standard Knife
	elseif commonitem == 2 then
		local mydata = playerdata[player.userId]
		mydata.standardknife = mydata.standardknife + 1
		local standardknifevalue = player:WaitForChild("Standard Knife")
		if standardknifevalue ~= nil then
			standardknifevalue.Value = mydata.standardknife
			event:FireClient(player , "Crate", "Common", "Standard Knife")
		end
	end
elseif cratetype <= 85 and cratetype >= 51 and cratetype < 86 then
	
	local craterarity = "Uncommon"
	local uncommonitem = math.random(1, 1)
	-- Neo Knife
	if uncommonitem == 1 then
		local mydata = playerdata[player.userId]
		mydata.neoknife = mydata.neoknife + 1
		local neoknifevalue = player:WaitForChild("Neo Knife")
		if neoknifevalue ~= nil then
			neoknifevalue.Value = mydata.neoknife
			event:FireClient(player , "Crate", "Uncommon", "Neo Knife")
		end
	end
elseif cratetype <= 99 and cratetype >= 86 and cratetype < 100 then
	print ("Rare")
	local craterarity = "Rare"
	local rareitem = math.random(1, 1)
	-- Old Reliable
	if rareitem == 1 then
		local mydata = playerdata[player.userId]
		mydata.oldreliableknife = mydata.oldreliableknife + 1
		local oldreliableknife = player:WaitForChild("Old Reliable")
		if oldreliableknife ~= nil then
			oldreliableknife.Value = mydata.oldreliableknife
			event:FireClient(player , "Crate", "Uncommon", "Old Reliable")
		end
	end
elseif cratetype == 100 then
	
	local craterarity = "Legendary"
	local legendaryitem = math.random(1, 1)
	
	-- Beta Knife
		if legendaryitem == 1 then
		local mydata = playerdata[player.userId]
		mydata.betaknife = mydata.betaknife + 1
		local betaknifevalue = player:WaitForChild("Beta Knife")
		if betaknifevalue ~= nil then
			betaknifevalue.Value = mydata.betaknife
			event:FireClient(player , "Crate", "Legendary", "Beta Knife")
		end
		else
			
			
	end
end
end

I'm sure you can tell how I'm doing this and I have ideas on why it doesn't work, I'm just not sure how to fix it.

Anything above 50 is uncommon regardless or my parameters for rare and legendary.

Thanks in advance.