Attempt to get length of a instance value error

Hello! For some reason my code keeps displaying this while trying to get audio from soundservice. help appreciated (Im trying to make it so the audio can not be heared further away)

local ContentProvider=game:GetService("ContentProvider");

audios = game.SoundService.NPC.Citizen.Talks:GetChildren()

while wait() do
		t = math.random(1,#audios)
		audios[t]:Play()
		task.wait(10)
		audios[t]:Stop()
end

Any help appreciated :slight_smile:

Have you define audios somewhere else? If not then change it to local audios.

Thank you! It seems that the problem has not vanished though. It just says the same error :frowning:

1 Like

I know this is an old question but I just happened to come across it and thought I could help. The error is caused by the :GetChildren() method being called on an instance value. If you want to get all of the children of the SoundService.NPC.Citizen.Talks instance value, you can do it like this:

Hi there! This issue is still here. I have had a look at your code but there isnt anything there? that might just be on my end but I can not see anything.

Try this

local ContentProvider=game:GetService("ContentProvider");

local audiostable = game.SoundService.NPC.Citizen.Talks:GetChildren()

local audios = {}

for i, v in ipairs(audiostable) do
    table.insert(audios, v)
end

while wait() do
		t = math.random(1,#audios)
		audios[t]:Play()
		task.wait(10)
		audios[t]:Stop()
end

Edit: I also don’t see his code so it’s probably not on your end.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.