#[SOLVED] Math Random Keep Choosing Same Values
55 messages · Page 1 of 1 (latest)
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
its print the same thing
basically i want one of these bool values to set to be true
choosenBoolvalue = chooseRandomKeyValue()
print(choosenBoolvalue.Name) -- print same thing
ReplicatedStorage.Values.BoolValues:GetChildren()[math.random(1, #ReplicatedStorage.Values.BoolValues:GetChildren())].Value = true
``` 👁👄👁
it choosing same thing
sometimes*
so you want to keep the previous pick and avoid picking that again?
like 20% chacne
yes
like set the previous pick value to false
same thing print
for some reason it works on random map
for the map . its work . for the bool value, its keep choosing same thing
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
alr lets see
If youre going to randomizer again just loop through do
for _, v in pairs(ReplicatedStorage.Values.BoolValues:GetChildren()) do v.Value = false end
randomizer = Randomizer(randomizer)
randomizer.Value = true
Just mess with it
its keep choosing same value
Dont set it back to nil, its the variable that stores the previous random
i didint
lemme test it again
it works
thx
[SOLVED] Math Random Keep Choosing Same Values
Thx @cosmic egret
cool
try this, removed the redundant getchildren bits
alr
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
.
local names = {["isKeyGreen"] = "Key Green", ["isKeyRed"] = "Key Red", ["isKeyYellow"] = "Key Yellow"}
local function Detect()
for _, v in pairs(Values:GetChildren()) do
if v.Value then return text.Text = names[v.Name] end
end
end
Youd have to call Detect() whether:
a while loop
fire a remotevent to client after randomizer
Mk