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

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

Asked by 6 years ago

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

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. Mineloxer 187 — 6y
0
Exactly what Mineloxer said. Tell the script to wait until the players character is found. Before you run the for loop. Impacthills 223 — 6y

1 answer

Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
6 years ago
Edited 6 years ago

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
Ad

Answer this question