Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
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

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
2 years ago

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
Ad

Answer this question