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

Why isn't my variable getting the list of items using an array?

Hello! I am trying to get the number of songs inside a folder to a variable I created using an array. But it doesn't do anything. Here's the localscript inside StarterPlayerScripts:

local musicfolder = game:GetService("ReplicatedStorage"):WaitForChild("Music")--I checked and it can find it
local musiclist = musicfolder:WaitForChild("Songs")--Same with this, it finds it
local global = #musiclist + 1
print("Global")--it doesn't print this.

1 comment

0

Mr Bruce you see you have to go on the view section , go on press a button that begins with ou and it will print

2 answers

✓ Accepted answer

change line 3 to

local global = #musiclist:GetChildren() + 1

so the whole code looks like this

local musicfolder = game:GetService("ReplicatedStorage"):WaitForChild("Music")it can find it
local musiclist = musicfolder:WaitForChild("Songs")
local global = #musiclist:GetChildren() + 1 --This changed
print("Global")

It's because you're not counting it's children, you're counting the object itself

1 comment

0

Thank you! It worked!

Mr Bruce you see you have to go on the view section , go on press a button that begins with ou and it will print

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