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

How do I make it so this table prints all it's strings to the output?

It doesn't print all the player's accessories in the output and it makes me sad :(

local script:

local tab = {}

for i,v in pairs (game.Players.LocalPlayer.Character:GetChildren()) do if v:IsA("Accessory") then table.insert(tab,v.Name) end end

for i = 1,#tab do print(tab[i]) end

2 comments

0

Your problem, is that the local script loads before the character and it's children, so it doesn't do anything. You should make it wait for the character to load before you start storing the accessories' names.

0

Exactly what Mineloxer said. Tell the script to wait until the players character is found. Before you run the for loop.

1 answer

✓ Accepted answer

Hello, You should always format your code using a code block, it makes it easier to see.

There's a few things wrong. You're most likely trying to run the script before the player's Character is loaded. You should use the same kind of for loop you used to make "tab" with printing tab, because you're only printing the number of the value of tab.

Here's how you can fix it:

local tab = {}
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()

for i,v in pairs (character:GetChildren()) do
	if v:IsA("Accessory") then
		table.insert(tab,v.Name)
	end
end

for i, v in pairs(tab) do
	print(v)
end

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