#How could I make something happen once two (or more) boolean values/attributes are set to true?

51 messages · Page 1 of 1 (latest)

paper isle
#

hi

simple yoke
#

hi

paper isle
#

you use an if statement

#

to check if those two booleans are true

simple yoke
#

yep i tried that, but it for some reason is only checking once

#

even if i change the values to true

paper isle
#

if table.find({A, B}, true) then

paper isle
simple yoke
#

in a code

paper isle
#

by typing it

simple yoke
#

yeah ik

paper isle
#
while true do
  if table.find({A, B}, true) then
    -- Code
  end
end
#

or just

#
while true do
  if A == true and B == true then
    -- Code
  end
end
median fossil
#

just use getpropertychanged or changed
or
check if the other value is true after setting the first one to true

paper isle
#

thats assuming he is talking about instance properties

median fossil
#

assumed he was since the whole attribute part

paper isle
#

then, use this

simple yoke
#

yeah uh

#

none of those worked🔥

paper isle
#

then give us more context

simple yoke
#

so

#

ive been trying to make 2 generators, and once they are triggered

#

their "active" values are set to true

#

i was wanting that a door opens once they are all true

median fossil
#

you sure you're doing things correctly on your side?

#

there's many ways to do this and if none are working then you might be doing something wrong

simple yoke
#

this is the generator code:```local prompt = script.Parent
local generator = prompt.Parent.Parent.Parent

local light1 = generator.light1
local light2 = generator.light2

local triggered = true
local triggered2 = true

function SwitchLights()
if triggered then
light1.BrickColor = BrickColor.new("Lime green")
light2.BrickColor = BrickColor.new("Black")
generator.sound:Play()
else
light1.BrickColor = BrickColor.new("Black")
light2.BrickColor = BrickColor.new("Really red")
generator.sound:Play()
end
triggered = not triggered
end

prompt.Triggered:Connect(function()

SwitchLights()

generator:SetAttribute("active",true)

prompt.Enabled = false

end)

#

is there smth wrong?

median fossil
#

looks fine, but where's the code where you check each generator's active value

simple yoke
#

lemme find the door

#

one sec

#

local generator1 = workspace.generator
local generator2 = workspace.generator2

local bool1 = generator1:GetAttribute("active")
local bool2 = generator2:GetAttribute("active")

if bool1 == true and bool2 == true then
    exitGate.Transparency = 1
    exitGate.CanCollide = false
    
    game.SoundService.GateOpened:Play()
end```
#

dis

median fossil
#
  1. that'll only check it once
  2. the values bool1 and bool2 will not update and only give you their values in the moment that the code was executed
simple yoke
#

how should I fix it?

median fossil
median fossil
#

combine the attributechanged event with the value checking part and you should be good

simple yoke
#

alright, thx

simple yoke
median fossil
#

whenever you run a regular script with a variable that gets a value of something

#

the value that it'll store is the one that it has in the moment

#

so if it updates

#

the stored value will stay the same and not update

#

, but if you re-check the value by using the same method of how you got it the first time it'll use the new updated value

simple yoke
#

ahh ok

#

i didnt know that

median fossil
#

it's a lot easier to see if you mess around with these things in-game