Counting script

so i have some models in a folder and i labeled them as like “Example_1”,“Example_2” and so on but thing is that i want to make a script to search for them in an ascending way without actually writing statements for each because i want to make it so you can add as many models as you would like, how do i do that???

2 Likes

(This was me assuming that you wanted this, please correct me if I made a mistake)

Check for the Item by Concatenating the Number with the Name, so in your Example (which is just Example_), you can specify what item you want by concatenating the strings, which basically just means adding them together, in this case we can combine x (our number) with Example using two dots .., for example:

local BaseString = "Example_" -- our normal string
local x = 5 -- our number

local CombinedString = BaseString .. x -- this is an example of Concatenation
local CombinedString2 = `{BaseString}{x}` -- is is another way of Concatenating
-- where you use backticks instead of quotes, and surround your item in Curly Brackets
-- to fill in the String

So after adding them together, you can then check if an Item exists using :FindFirstChild():

local Object = Example:FindFirstChild(BaseString .. x)
-- :FindFirstChild() will attempt to look for this object
-- if the object cannot be found, it will return nil
-- so we check whether it was found via if statement
-- like this example below:

if Object then  -- if the object was found
    -- fire code
end

that is something close to what i need but the script should be fully automatic meaning that you should not change the code every time you add another model