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

How do i put tools from replicatedstorage in a table?

Asked by
Zrxiis 26
7 years ago

How would i make a script that would get tools from ReplicatedStorage and put them in the table?

2 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

GetChildren

GetChildren is one of many inherited members of the Instance base class (see here), which means you can call it on any ROBLOX object. This method will return a table (specifically, an array or list), of all the children inside the object you called it on. Here's an example:

local RepStorage = game:GetService("ReplicatedStorage") -- Get service
local RepStorageContents = RepStorage:GetChildren() -- Call GetChildren on service

-- Iterate through the contents GetChildren returned, printing out their individual names.
for k, v in pairs(RepStorageContents) do
    print("Index:", k, "Object:", v)
end

If you're confused about anything, just leave a comment letting me know; I'll respond as soon as possible.

0
Is there a way that I could put each of the individual names into textboxes? Zrxiis 26 — 7y
0
Yes. The list contains all of the objects inside the object you called the method on. You can iterate this list like I have in my sample code, access these objects individually, and do whatever you like with them. ScriptGuider 5640 — 7y
0
Thx for the help :) Zrxiis 26 — 7y
0
How would I print out their individual names? Zrxiis 26 — 7y
Ad
Log in to vote
-2
Answered by
Scrxptss -13
7 years ago
local Tools = game:GetService('ReplicatedStorage')
tools = {}

Tools.ChildAdded:connect(function(Child)
    if Child:IsA("Tool") then
        table.insert(tools, Child.Name)
        print('Inserted tool name into table')
    end
end)

NOTE Another script is required to use this.

wait(1)
local tool1 = game.TOOLPLACE
local tool2 = game.TOOLPLACE
wait(1)
tool1.Parent = game:GetService('ReplicatedStorage')
tool2.Parent = game:GetService('ReplicatedStorage')

NOTE Do not put tools in replicated storage.

If this is not what you looked for sorry. And I know there is a easier way of doing this, this is my personal way to go.

Answer this question