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

How to use GetChildren() to get the names of string values in a folder?

Asked by
LaysCo 61
3 years ago
Edited 3 years ago

So when i loop and check for a folders name it doesn't get the names and instead does it like they don't exist. A solve would be very helpful thanks. No output errors. I have string values that get added into the folder

local v = script.Parent.Parent.Values

local function makeLookupTable(table)  -- Utility function to create a lookup table
    for i = 1,#table do
        table[table[i]] = true
    end
    return table
end

local whitelist =   makeLookupTable({script.Parent.Parent.Parent.Parent.whitelists:GetChildren()}) --problem seems to be here

script.Parent.MouseButton1Down:Connect(function()
    script.Parent.Parent.Values.count.Value = script.Parent.Parent.cmdcount.Text
    if v.torf.Value == false then
        v.torf.Value = true
        script.Parent.Text = "LOOPING"
        -------------------------------------------------------------
        while wait(v.wait.Value) do
            if v.torf.Value == true then
                for _, player in ipairs(game.Players:GetPlayers()) do
                    if not whitelist[player.Name] then
                        game:GetService'Players':Chat(":"..tostring(script.Parent.Parent.cmd.Text).." "..tostring(player.Name).." ")
                    end
                end
            end
        end
    elseif v.torf.Value == true then
        v.torf.Value = false
        script.Parent.Text = "OFF"
    end
end)
0
I don't know how "toe" get "children" names in a folder. WideSteal321 773 — 3y
0
to* just an error LaysCo 61 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

It looks like in line 10, that you are inserting a table in a table. Just try again but this time, remove the {}, because :GetChildren() provides you a table of arrays.

Edit : After printing results by replicating your code, I have found the error.

-- In Line 21, Instead of
if not whitelist[player.Name] then -- It returns the value nil, so your code continues even if the name is there

-- You must do
if not table.find(whitelist, player.Name) then -- Finds the name of the player in the whitelist table

Edit 2 : I re-checked your code and using :GetChildren() for instances. And the following code might work.

local blahblah = game.ReplicatedStorage.Folder:GetChildren()

local function TableFinder(Name, Array)
    for _, Nam in ipairs(Array) do
        if Name.Name == Nam.Name then
            -- Do if the name is in the whitelist
        else
            -- Do if the name isn't in whitelist
        end
    end
end

TableFinder(player, blahblah) -- In your case, it's whitelist.

Lemme know if it helps!

0
That still doesn't work, when it chats i want it to only chat the players names that are'nt in the folder. LaysCo 61 — 3y
0
still doesnt do what i want it to do LaysCo 61 — 3y
0
Edited it, it might work now BestCreativeBoy 1395 — 3y
Ad

Answer this question