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

How can I assign a random BoolValue?

Asked by 6 years ago
Edited 6 years ago

Basically I want this door to randomly chose a BoolValue (true or false)

Right now I have it changing by an if statement.

while true do
    wait(Config.Wait.Value)
    if Config.RandomKill.Value then
        if Config.Kill.Value then
            --Door.BrickColor = BrickColor.Random()
            Config.Kill.Value = false
        else
            --Door.BrickColor = BrickColor.Random()
            Config.Kill.Value = true -- I want this to randomly change it not by if statement
        end
    end
end

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

Well what you can do is use math.Random() and if it is one number make it true and if it is another number make it false.

local bool=false
local n = math.random(1,2)
if n==1 then bool=true elseif n==2 then bool=false end
0
You could also evaluate it with a relational operation: local b = math.random(2) == 1 ScriptGuider 5640 — 6y
0
BTW, add math.randomseed(tick()). Or else it wont be random User#17125 0 — 6y
0
I would recommend putting it in tables, it makes things easier saSlol2436 716 — 6y
Ad

Answer this question