Math.random problem

This script should give the player rocks or paper or print nothing but for some reason its only giving rocks and not paper or print nothing. i even pressed the button 1000 times and i got 289 rocks 0 papers no got nothing in output. heres the script

local mainGui = script.Parent.Parent.Parent
local itemButton = script.Parent
local moneyHandler = game:GetService("ReplicatedStorage"):WaitForChild("MoneyHandler")
local inventory = mainGui.Inventory

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local money = leaderstats:WaitForChild("Money")

itemButton.MouseButton1Up:Connect(function()
	
	local randomNumber = math.random(1,100)
	
	if randomNumber <= 35 then
		
		local rarityItem = math.random(1, 100000)
		
		if rarityItem <= 45000 then
			
			local commenItem = math.random(1,10)
			
			if commenItem == 1 or 2 or 3 or 4 then -- I do get rocks
				local amountGettingItemRock = math.random(1,100)

				if amountGettingItemRock <= 70 then
					inventory.ItemsScrollingFrame.Rock.AmountItem.Value += 1
				elseif amountGettingItemRock <= 94  then
					inventory.ItemsScrollingFrame.Rock.AmountItem.Value += 2
				elseif amountGettingItemRock <= 100 then
					inventory.ItemsScrollingFrame.Rock.AmountItem.Value += 3
				end
				
			elseif commenItem == 5 or 6 or 7 then -- but no paper
				local amountGettingItem = math.random(1,100)
				
				if amountGettingItem <= 70 then
					inventory.ItemsScrollingFrame.Paper.AmountItem.Value += 1
				elseif amountGettingItem <= 94  then
					inventory.ItemsScrollingFrame.Paper.AmountItem.Value += 2
				elseif amountGettingItem <= 100 then
					inventory.ItemsScrollingFrame.Paper.AmountItem.Value += 3
				end
			elseif commenItem == 8 or 9 or 10 then
				print("got nothing") -- and I also dont get this message
			
			end
		end
	elseif randomNumber >= 36 then
		print("Dint get reaction") -- I do get this in the chat
	
	end
	
end)

can someone please help me?

Programming doesn’t work the same as English. Do this instead.

if commenItem == 1 or commenItem == 2 or commenItem == 3 or ...
1 Like

Small thing, would it be faster to do this?

if commenItem > 0 and commenItem < 4 then

or:

if commenItem < 4 then
1 Like

It could probably be faster, but if it was no one would notice. But it is a better way of checking the value.

1 Like

Give the solution to @JarodOfOrbiter , not me.

1 Like

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