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

[SOLVED] Attempt to call method 'GetChildren' (a nil value)?

Hello dear scriptinghelpers community. I am currently creating a Children counting Plugin for myself. (Maybe I'll upload it later). It's basiclly counting the children an Instance has. Here's a Code snippet: (Runs when the button in the toolbar is pressed)

	local Selection = game:GetService("Selection")
	local Selected = Selection:Get()
	if(#Selected == 1)then
		local Children = #Selected:GetChildren()
		warn("[Doge's part counter] "..Selected:GetFullName().." has "..Children.." children.")
		showResults(Selected:GetFullName(),Children)
	elseif(#Selected == 0)then
		GuiError("Nothing is selected.")
	else
		GuiError("More than 1 thing is selected.")
	end

When I select a script and press the toolbar button there Comes an error:

11:19:22.560 - PartCounter.lua:198: attempt to call method 'GetChildren' (a nil value) 11:19:22.561 - Stack Begin 11:19:22.561 - Script 'PartCounter.lua', Line 198 11:19:22.561 - Stack End

Weird About this is that when I enter

game.ServerScriptService.PartCounter.PartCounter:GetChildren()

into the lua console in Studio it prints: (as exspected)

table: 0000022F3000A5A0

Is there any way to fix this?

1 answer

✓ Accepted answer

The problem is that Selected is a table and on line 5 you are treating it like an instance. You probably meant to do Selected = Selected[1] (after line 3) or Selected[1]:GetFullName() on line 5 instead of Selected:GetFullName()

3 comments

0

OMG I JUST NOTICED EXACTLY THAT.

0

Thanks anyways.

0

Don't forget to mark an answer as "accepted" or to modify your question title to include "[Solved]" so people know it's figured out

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