#Trying to check if ANY item from an array exists.

1 messages · Page 1 of 1 (latest)

frosty rover
#

Im starting to learn LUAU, but ive run into this little issue.
I have an array of 6 items, and im trying to check if at least 1 of them exists without having to check 1 by 1.

Thx in advance :D

#

Also for if it helps. Currently im just trying out LUAU in general so im trying to script random stuff.

Heres the current script that im using for this randomizer. Everything works but the checking array since i cant use "firstchild" on it

#

tried to send the current script and this happened

#

`while true do

if workspace:FindFirstChild(partArray) then
    print("Already Spawned!!")
else
    local RNG = math.random(0,1000)
    if RNG >= 0 and RNG <= 10 then -- 0.1
        local respawnPart6 = partClone6:Clone()
        respawnPart6:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart6.Parent = workspace
    elseif RNG >=11  and RNG <=60 then -- 5
        local respawnPart5 = partClone5:Clone()
        respawnPart5:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart5.Parent = workspace
    elseif RNG >=61  and RNG <=160 then -- 10
        local respawnPart4 = partClone4:Clone()
        respawnPart4:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart4.Parent = workspace
    elseif RNG >=161  and RNG <=310 then -- 15
        local respawnPart3 = partClone3:Clone()
        respawnPart3:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart3.Parent = workspace
    elseif RNG >=311  and RNG <=560 then -- 25
        local respawnPart2 = partClone2:Clone()
        respawnPart2:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart2.Parent = workspace
    elseif RNG >=561  and RNG <= 1000 then -- 45
        local respawnPart1 = partClone1:Clone()
        respawnPart1:PivotTo(CFrame.new(spawnPos, lookAtPos))
        respawnPart1.Parent = workspace
    end
    print(RNG)
end

wait (5)

end`

wild nimbus
#

Can’t do it with an array

frosty rover
#

hmmm thats sad

#

is there anyway to do it through a list?

wild nimbus
#

Also I don’t know what you’re trying to do still

frosty rover
wild nimbus
#

So I can’t tell you what the proper way to do it is

frosty rover
#

so like im tryna make a lil randomizer that spawns a colored brick depending on the number given by the variable RNG on the 5th line.

Thing is i want it to spawn 1, and not spawn any more until that one is gone

#

Let me send you the whole thing

#

i might have to send it in a file since it doesnt fit here ^^"

#

@wild nimbus tell me if you need more info and ill gladly oblige

wild nimbus
#

So you only want it to spawn something from the array if it sees that nothing from the array is already spawned?

frosty rover
#

oh and if youre curious

#

this what happens if i leave it for a few seconds

wild nimbus
#

What’s in the array?

frosty rover
#

Basically the local partClone1 = workspace.Testing.Testparts["Rarity 1"] partClone1.Name = "Rar1" partClone1.Parent = replaceItems

#

im trying to explain myself hol on

#

basically it just sets up the bricks to be cloned under a new name and indexed in a folder that contains them

#

the array contains the cloned versions of the brick

wild nimbus
#

Use the array to hold the parts to be cloned, then when cloning a part parent it under a folder made specifically for the cloned parts. Then all you have to do is check if folder:GetChildren() returns a list with anything in it

frosty rover
cobalt foxBOT
#

studio** You are now Level 2! **studio

frosty rover
#

so, if the folder has no children and i do that

#

it will just give me nil?

wild nimbus
#

No, it’ll always return an array. If it has no children the array will be empty

#

If it has no children*

frosty rover
#

?

#

i bricked studio again xd

frosty rover
#

Did it!

#

@wild nimbus

#

thx for the help!

heady hull
#

So you never have to do this else if crap again

frosty rover
heady hull
#

now that im on pc

#

local partArray = {nil, nil, nil,, nil, nil, nil}

#

and then youre checking for workspace:FindFirstChild(partArray)

#

(findfirstchild takes a string)

frosty rover
#

Yeah what i did for that is just make an array that gets updated with the children in a folder, then it checks if the folder is empty, if it is, it spawns a new piece :D

heady hull
#

oh

frosty rover
#

Im slowly understanding how types of data work in LUAU

heady hull
#

you got it

#

I hadnt seen that

frosty rover
#

If you are curious about the whole script i can send it to you btw :D

cobalt foxBOT
#

studio** You are now Level 3! **studio