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

why does it keep printing the number 5 even though it should print 25 every time the number is 10?

num = 5
mult = 5
while true do
    wait(0.25)
    math.random(1,10)
    if math.random() ~= 10 then
        print(num)
    elseif math.random() == 10 then
        print(num * mult)
    end
end

i'm trying to make an rng system that prints the number if the number that was picked was not equal to 10 if the number is equal to 10 it will multiply the number by 5 but for some reason, it doesn't seem to work as expected it should have a 10% chance of printing the number 25 but it keeps printing 5 how do i fix this?

1 answer

math.random() returns a value of 0 to 1 so asking if math.random() ~= 10 then will always be true but elseif math.random() == 10 then will always fail. To fix your code, I would change it to the following:

local num = 5
local mult = 5
while true do
	wait(0.25)
	local Chance = math.random(1,10)
	if Chance ~= 10 then
		print(num)
	elseif Chance == 10 then
		print(num * mult)
	end
end

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