So I have this code:
local SquareTable = {"Square1", "Square2", "Square3", "Square4", "Square5", "Square6", "Square7", "Square8", "Square9", "Square10", "Square11", "Square12", "Square13", "Square14", "Square15"} for i,v in pairs(game.ServerStorage:WaitForChild("Parts"):WaitForChild("Squares"):GetChildren()) do if v.Name == table.concat(SquareTable) then v:Clone().Parent = game.Workspace end end
I'm checking to see in the ServerStorage if the part's name are equal to the Square name.
There are 15 parts in the Squares folder inside of the server storage, and they are all named Square1, Square2, etc. As it follows to Square15. But I'm placing those names in a table and then I'm concating it to get all the values of the table and to see if all the parts in the Squares folder are equal to the SquareTable. However, this does not work. I get no error, i get nothing. So what's the solution? What am I doing wrong?
table.concat returns a string of the items in the table.
Ex;
local Table = { "A", "simple", "table.concat", "test" } print( table.concat( Table ) )
This would return;
Asimpletable.concattest
But why are you getting no error or output.. Well, if you compare the v.Name (Square1) to the cancat table which would be all the names, Square1Square2..etc. it would not pass the if statement- there is your problem.
For this task you want to complete, I don't think table.concat is the best way to come of this.
If you still want to do concat, try to do a gmatch in the string. Ex;
local tableArray = { "A1", "A2", "A3", "A4" } local tableCat = table.concat(tableArray) local partFolder = workspace.Squares -- example for i,v in pairs (partFolder:GetChildren()) do if string.gmatch(v.Name, tableCat) then -- its in the table else -- not in the table end end
In your case you want to check to match the table with the explorer tree-
local SquareTable = {"Square1", "Square2", "Square3", "Square4", "Square5", "Square6", "Square7", "Square8", "Square9", "Square10", "Square11", "Square12", "Square13", "Square14", "Square15"} local Squares = game.ServerStorage:WaitForChild("Parts"):WaitForChild("Squares"):GetChildren() -- now you have both tables.. now compare them if table.concat(SquareTable) == table.concat(Squares) then -- if tables match then for i,v in pairs (Squares) do -- itterate thru squares in folder to replicate to workspace v:Clone().Parent = game.Workspace end end
If this helped, please accept this answer! :D