#[SOLVED] Math Random Keep Choosing Same Values

55 messages · Page 1 of 1 (latest)

next nexus
#

I try to prevent it but its still happening

#
local function chooseRandomKeyValue()
    local currentBoolValue = nil
    local previousBoolValue = nil
    
    
    
    local BoolValuesFolder = game:GetService("ReplicatedStorage").Values:WaitForChild("BoolValues"):GetChildren()
    
    
    repeat 
        currentBoolValue = BoolValuesFolder[math.random(1,#BoolValuesFolder)]
        wait()
    until currentBoolValue ~= previousBoolValue
    if currentBoolValue ~= previousBoolValue then
        local choosenBoolValue = currentBoolValue
        return choosenBoolValue
    end
    
end
cosmic egret
#

What does it print

#

I mean what is the value

next nexus
#

its print the same thing

cosmic egret
#

what is the value?

#

What number

next nexus
#

basically i want one of these bool values to set to be true

#
choosenBoolvalue = chooseRandomKeyValue()
print(choosenBoolvalue.Name) -- print same thing
cosmic egret
#
ReplicatedStorage.Values.BoolValues:GetChildren()[math.random(1, #ReplicatedStorage.Values.BoolValues:GetChildren())].Value = true
``` 👁👄👁
next nexus
#

sometimes*

cosmic egret
next nexus
#

like 20% chacne

next nexus
#

like set the previous pick value to false

next nexus
#

for some reason it works on random map

#

for the map . its work . for the bool value, its keep choosing same thing

cosmic egret
#
local function Randomizer(prev)
    local randomNum, values = math.random(1, #ReplicatedStorage.Values.BoolValues:GetChildren()), ReplicatedStorage.Values.BoolValues:GetChildren()
    if values[randomNum] == prev then
        task.wait()
        Randomizer(prev)
    end
    return values[randomNum]
end

local randomizer = nil
randomizer = Randomizer(randomizer)
randomizer.Value = true
next nexus
#

alr lets see

cosmic egret
#

Just mess with it

cosmic egret
#

Rng is good

#

did you set randomizer to nil again?

next nexus
#

wait

#

hold on

cosmic egret
#

Dont set it back to nil, its the variable that stores the previous random

next nexus
#

lemme test it again

#

it works

#

thx

#

[SOLVED] Math Random Keep Choosing Same Values

#

Thx @cosmic egret

cosmic egret
next nexus
#

i need 1 mor help

#

its client script

#

and its ui

cosmic egret
next nexus
#
local function detectAllValues()
    while wait(5) do -- check the values every 5 seconds
        if Values.isKeyGreen.Value == true then
            text.Text = "Key Green"
        elseif Values.isKeyRed.Value == true then
            text.Text = "Key Red"
        elseif Values.isKeyYellow.Value == true then
            text.Text = "Key Yellow"
        end
    end
    
end

for some reason it didint update

#

like if the text turn to key green

#

it gonna keep for ever

#

.

cosmic egret
next nexus
#

oo thx

#

that is so good

cosmic egret
next nexus
#

ok

#

thx

#

i gtg

#

sleeping

cosmic egret
#

Mk