Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How can you store multiple things in workspace that have the same name in an array?

Asked by 9 years ago

How can you store multiple things in workspace that have the same name in an array?

0
Can you explain why you would want to do that, and what do you mean by "array" and "name"? BlueTaslem 18071 — 9y
0
I have multiple ammo tables in a map, I want to store them on an array inside a script which is inside the gun and I want to cycle through them to check if one is within range of the player dragonkeeper467 453 — 9y

2 answers

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago
myTable = {} --Your table.
desiredName = "YourDesiredName" --Your desired name.

for i,v in pairs(game.Workspace:GetChildren()) do --Set up for loop for Workspace's childre.
    if v.Name == desiredName then --Check if the name is the same.
        table.insert(v, myTable) --Insert the instance if the name is the same.
    end
end

If I helped you out, make sure to hit the Accept Answer button below my character! :D

0
thanks so much! dragonkeeper467 453 — 9y
Ad
Log in to vote
9
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your question is pretty broad.. but i'll try to help. You should definitely elaborate on what you want.

If you mean that you have an array full of names, and if there's an object in the workspace with a name that matches a name in the array then parent it somewhere else then..

First, you should define the array

local names = {"Thing","Thing1","Thing2","Thing3"}

Then you should iterate through the table, and use an if statement to check if there's a part with the same name in workspace.

for i,v in pairs(names) do
    local obj = workspace:FindFirstChild(v)
    if obj then

And lastly you should store it by parenting it to wherever you want. Here's it all together.

local names = {"Thing","Thing1","Thing2","Thing3"}

for i,v in pairs(names) do
    local obj = workspace:FindFirstChild(v)
    if obj then
        obj.Parent = --Put the parent here
    end
end
0
yes, that would work as well, I like the script discern shared better though, its exactly what I need and he posted before you, but I gave you a rep point for the help dragonkeeper467 453 — 9y

Answer this question