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

trying to set string names from a table but, ends up setting it all to one name, help??

Asked by 5 years ago
local data = {"noob", "string", "NeilTheGreat"}
for _, v in pairs(data) do        ------------------- this entire section needs help.
            print(v)
            local stringName = v
            for _, ayo in pairs(workspace.Folder:GetChildren()) do
                ayo.Name = stringName
            end
        end

What I am basically trying to do here is, there is a folder with plain string values, in fact 3 string values. When I try to change their name to the items in data, it ends up changing it to NeilTheGreat each time for all of the values. And since I want it random, [1], [2], [3] won't work. Any help would be gr8! thanks

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
5 years ago

Give this a try, not sure if it will work:

local data = {"noob", "string", "NeilTheGreat"}
for i, v in pairs(data) do 
    print(v)
    local stringName = v
    for ii, ayo in pairs(workspace.Folder:GetChildren()) do
        if i == ii then
            local num = i
            ayo.Name = data[num]
        end
    end
end
0
Ok I will test it in a while just not right now, i will accept if it works otherwise I will ask you if there is an error or not. Thanks for the nested loop help. greatneil80 2647 — 5y
0
Thank you so much! greatneil80 2647 — 5y
Ad

Answer this question