Hi
so i’m Still kinda new to roblox studio and i want to know how
how do I set 1 Variable to true Once Find 1 value True inside table (used for Loops)?
Hi
so i’m Still kinda new to roblox studio and i want to know how
how do I set 1 Variable to true Once Find 1 value True inside table (used for Loops)?
dictionary table:
local yourTable={
['element1']=false,
['element2']='abcdefg',
['element3']=true,
['element4']=false
}
for index,key in pairs(yourTable)do -- loop through the table
if key==true then
-- if you write 'if key then' then everything except 'false' will be found, even if it is a string
print(index,key,' is true')
end
end
default table:
local yourTable={
false,'abcdef',false,true,false
}
for i,k in pairs(yourTable)do
if k==true then
print(k,' is true')
end
end
I see but what if the elements is changed every 0.1 sec to random values?
Sorry what I mean is what If the Elements is a Part on The Workspace and changed color to random color every 0.5 sec and How do set the Variable to true Once Find a color of Red and if none of the part is red the var turn to false?
I see you want a constant check.
Spawn a function where you use a while loop to check every 0.1 sec.
Yeah like that but Part, do you know how to make it?
OK I’ll do some code rn but I’m on mobile so expect done typos
local var = false
task.spawn(function()
while var == false do
for i, v in ipairs(table) do
if v==true then
var = true
end
end
task.wait(0.1)
end
end)
Sorry I cannot tab on phone…
I had misread ur topic I fixed the code now.
local parts = {
workspace.Part1,
workspace.Part2,
workspace.Part3,
workspace.Part4,
}
-- every second set the parts to a random color
while true do
local redAmount = 0
-- loop all parts in the parts table
for i, part in parts do
-- get random red, green and blue values
local r, g, b = math.random(), math.random(), math.random()
-- set the parts color
part.Color = Color3.new(r, g, b)
-- if there is more then 50% red in the part add 1 to the redAmount value
if r > 0.5 then redAmount += 1 end
end
-- set the intValue inside of ReplicatedStorage to redAmount so other script can find out how many red parts there is
game.ReplicatedStorage.IntValue.Value = redAmount
task.wait(1)
end
this will set a intvalue to the amount of parts that are red
then to find out if there are any read parts all you do is
if game.ReplicatedStorage.IntValue.Value == 0 then
print("There are no red parts")
else
print("There are" , game.ReplicatedStorage.IntValue.Value, "red parts")
end
it works, thank you very much everyone for helping me :]