#How could I make something happen once two (or more) boolean values/attributes are set to true?
51 messages · Page 1 of 1 (latest)
hi
yep i tried that, but it for some reason is only checking once
even if i change the values to true
if table.find({A, B}, true) then
then use a while loop
by typing it
yeah ik
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
just use getpropertychanged or changed
or
check if the other value is true after setting the first one to true
thats assuming he is talking about instance properties
assumed he was since the whole attribute part
then, use this
then give us more context
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
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
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?
looks fine, but where's the code where you check each generator's active value
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
- that'll only check it once
- the values
bool1andbool2will not update and only give you their values in the moment that the code was executed
how should I fix it?
to fix the problem of it only checking once
don't store the values and instead check their "live" ones (however you want to say it)
e.g.
while true do
if generator1:GetAttribute("active") and generator2:GetAttribute("active") then
--///
end
task.wait(1)
end
combine the attributechanged event with the value checking part and you should be good
alright, thx
but just one question, why would this work and not the other one?
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
it's a lot easier to see if you mess around with these things in-game