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 reference a child using a table?

I'm trying to use strings in a table to reference children of intvalues in a folder, however, it errors, saying things like "(arrayname) is not a valid member of Folder" and I've tried so far to do things like this (some code may seem strange):

local stats = game.Players.LocalPlayer:WaitForChild("LeaderStats")

local Index = {"IntValue1", "IntValue2", "IntValue3", "IntValue4"}

local priority = {4, 2, 3, 1}

for i = 1, stats.SeperateValue.Value do
	for i = 1, #priority do
		if stats:WaitForChild(Index[priority[i]]).Value > 0 then
			--blah blah blah
			break
		end
	end
end

Also, just as another small question, would the "break" end every single loop, or just the one for loop it's nested inside of?

1 answer

✓ Accepted answer

How do we access something with dot notation?? Very simple You put the index that you want inside a variable inside the table

local stats = game.Players.LocalPlayer:WaitForChild("LeaderStats")

local Index = {
IntValue1 = stats.Stat1, -- or stats
IntValue2= stats.Stat2, 
IntValue3 =stats.Stat3, 
IntValue4 = stats.Stat4
}

local priority = {4, 2, 3, 1}

for i = 1, stats.SeperateValue.Value do
    for i = 1, #priority do
        if stats:WaitForChild(Index[priority[i]]).Value > 0 then
         		Index.IntValue1.Value = 1 -- This is an example code
            break
        end
    end
end

Hopefully this helped you Please submit this answer if it worked

2 comments

0

Thanks, it works!

0

Your welcome!!

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