So for my game kind of like lt2, i need to cycle through a table of tree models. inside those models i have a bool value set to false by default. I got the table by doing game.ReplicatedStorage.OakTrees:GetChildren() and I want to do a math.random() to go through it but if i check if the value is false, how do i make it do math.random again? because if it does that and its still false, it could keep the process going and i dont want to have like 1 million else statements. Thanks for the help!
Sounds like you need to use a repeat ... until
loop. Which would fit into your case like this:
local trees = workspace.Trees:GetChildren() local option repeat option = trees[math.random(1, #trees)] until option.BoolValue.Value == true
If I were you, I'd use a for i,v in pairs
loop instead:
function getFirstTree() for index, value in pairs(trees:GetChildren()) do if value.BoolValue.Value == true then return value end end end local option = getFirstTree()