So im trying to make a stand system where you picks a random stand but I dont want it to pick a stand with a value named "Private" in it. I just dont know a efficant way to keep picking a random one untill it finds one without the tag. This is the script that picks it:
local Stand = game:GetService("ServerStorage").Stands local items = Stand:GetChildren() local randomStand = items[math.random(1, #items)] if randomStand:FindFirstChild("Private") == nil then return else local randomStand = items[math.random(1, #items)] end
Thanks in advanced
You need to filter out private stands with public ones and then select random one from the public ones, using ipairs loop it should not be a problem
local Stand = game:GetService("ServerStorage").Stands local items = Stand:GetChildren() local public = {} for _, Item in ipairs(items) do if not (Item:FindFirstChild("Private")) then table.insert(public, Item) end end local randomStand = public[math.random(1, #public])
I hope you get the idea. Read about loops here if you don't understand them.
If you want to repeat something until stand is not picked, you can simply repeat a function if the stand is not private, can look like this
local function FindStand() local randomStand = items[math.random(1, #items]) if (randomStand:FindFirstChild("Private")) then FindStand() else print('Found') end end FindStand()
If the stand is private, it will call FindStand
again which will do the same thing but will select other stand.
local Stand = game:GetService("ServerStorage").Stands local items = Stand:GetChildren() local randomStand = items[math.random(1, #items)] if randomStand:FindFirstChild("Public") == nil return else local randomStand = items[math.random(1, #items)] local randomStand = items[math.random(1, #items)] if randomStand:FindFirstChil("Private") == nil then --Idk if this is the right answer so ye test it out.