Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to find and name all tools in backpack?

Okay,

Basically I have a script that checks through your backpack to read out all of the tools the player has in output.

If it is working, when the player steps on a brick, it should go in the output and read out the tools something like this:

Tool A, Tool B, Tool C, -- continues going

Currently, my code looks like this and I can't seem to figure out how to convert the table into a string and get it all in one print. I have been successful at getting it out in 3 seperate prints using unpack() but that's not what I wanted to do.

local c = plr.Backpack:GetChildren()
local backpack = {}

for i = 1,#c do
	if c[i]:IsA("Tool") then
		table.insert(backpack, c[i])
	end
end

print() -- output goes here

Thanks, tgarbrecht

2 comments

0

Did you print(backpack)? If that does not work, maybe try this: print(backpack:GetChildren())?

0

yes, printing backpack by itself will just return a table value and backpack:GetChildren() errors. i've been on this for hours and can't seem to find out a way to get it formatted correctly or even work without formatting it

1 answer

✓ Accepted answer

It seems like you were attempting to print out the tool instances, but wanted to print out the tool names. This should work:

local c = plr.Backpack:GetChildren()
local backpack = {}

for i = 1,#c do
    if c[i]:IsA("Tool") then
        if i == #c then
            table.insert(backpack, c[i].Name)
        else
            table.insert(backpack, c[i].Name..", ")
        end
    end
end

print(unpack(backpack))  --This will print each of the values in "backpack", each separated by a comma (except for the last value)

3 comments

0

Thank you so much, it works. Any way to separate it with commas or no?

0

Nevermind, figured it out on my own.

0

Yep. If anything, I updated the post so that the values are separated by commas.

This discussion is preserved as it was. New answers, comments, and votes are closed.