I want to make it so if the Model's name is Rock1 or Rock2 it will print yey. I do not want to use two if statements, so can you please tell me whats wrong in line 3?
area = {1,2} game.Workspace.ChildAdded:connect(function(part) if part.Name == "Rock"..#area and part:IsA("Model") then print("yey") end end)
"Rock" .. #area
is just "Rock2"
.
If you mean "Rock"
and then a number...
if part.Name:match("Rock%d+") == part.Name then -- %d means digit -- %d+ means at least one digit -- :match returns the "longest" result that is the thing -- so we need it to be the *whole* thing, which is `part.Name`
It might be simpler to just say "begins with "Rock"
":
if part.Name:sub(1, 4) == "Rock" then
If you mean the name is contained in the list rockNames
, then you would have a loop (or a function which uses the loop, which I'll do here)
function contains(tab, element) for _, value in pairs(tab) do if value == element then return true end end end ..... if contains( rockNames, part.Name) then
Overall, it would be better to use a consistent name/detection method for all "Rock"
objects (if not name, then for instance :FindFirstChild("Rock")
)
They are all Rocks. If you want to give them a number, use a NumberValue or IntValue object. etc.