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

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

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)

2 comments

0

I don't know how "toe" get "children" names in a folder.

0

to* just an error

1 answer

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!

3 comments

0

That still doesn't work, when it chats i want it to only chat the players names that are'nt in the folder.

0

still doesnt do what i want it to do

0

Edited it, it might work now

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