Attempt to call a nil value when using GetChildren()

I want to make this so it doesn’t occur in an error and continues the bosses attacks, however it is saying Attempt to call a nil value for some reason when there is stuff in the folder/model I’m selecting.

local v1 = game:GetService('ServerStorage'):WaitForChild('Gaster Test')
local v2 = game:GetService('ServerStorage'):WaitForChild('Gaster Test1'):GetChildren()
local i__humanoidrootpart__i = script.Parent.HumanoidRootPart
local v3 = nil
local v4 = nil
local v5 = false
local v6 = false

function fireBeam()
	v5 = true
	v3 = v1:Clone()
	v3.Parent = workspace
	v3:SetPrimaryPartCFrame(i__humanoidrootpart__i.CFrame)
	v3:TranslateBy(Vector3.new(5, 5, 5))
	task.wait(5)
	v3:Destroy()
	v5 = false
end

function fireTrioBeam()
	v6 = true
	v4 = v2:Clone()
	v4.Parent = workspace
	v4:SetPrimaryPartCFrame(i__humanoidrootpart__i.CFrame)
	v4:TranslateBy(Vector3.new(5, 5, 5))
	task.wait(5)
	v4:Destroy()
	v6 = false
end

while true do
	if v5 == false then
		fireBeam()
	if v6 == false then
		fireTrioBeam()
		end
	end
end

Help as always would be greatly appreciated!

That sounds like a pretty common error. If you’ve tried figuring it out already and still need help, could you share the full error message and all of the relevant context to reproduce the bug?

As a side note based on the code that you have shared, it would be helpful to give the variables meaningful names. It helps when debugging and just the general understanding of what is trying to be done with the code
For example: “v1” and “v2” could instead be named “gaster”, “gaster1Children”,

Probably not your issue, but I would start by getting rid of the spaces in your folder names: Maybe “GasterTest” instead of “Gaster Test”.

Also, be absolutely sure you don’t have two folders with the same name in the ServerStorage folder.

That’s odd that you’re getting a nil value on using GetChildren on a variable that you used WaitForChild on. I expected that error to most likely to occur after the yields (task.wait) because you don’t check if the values are real or not before destroying them. Is there other scripts that are deleting/niling v2?

Is this a serverscript or localscript?

It’s a server script, I dont know what affect that would do to it though,

No there isn’t its just an array of models in a fodler that I am trying to get but it won’t seem to work by calling it nil

I’ve done this and I dont know why it doesn’t work it calls out

Workspace.Boss.Attacks:22: attempt to call a nil value
Stack Begin  -  Studio
Script 'Workspace.Boss.Attacks', Line 22 - function fireTrioBeam  -  Studio - Attacks:22
Script 'Workspace.Boss.Attacks', Line 35  -  Studio - Attacks:35
Stack End  -  Studio

and I’ve changed my code to

local i__GasterTest__i = game:GetService('ServerStorage'):WaitForChild('GasterTest')
local i__GasterTestMulti__i = game:GetService('ServerStorage'):WaitForChild('GasterTest1'):GetChildren("GasterTest")
local i__humanoidrootpart__i = script.Parent.HumanoidRootPart
local v1 = nil
local v2 = nil
local v3 = false
local v4 = false

function fireBeam()
	v3 = true
	v1 = i__GasterTest__i:Clone()
	v1.Parent = workspace
	v1:SetPrimaryPartCFrame(i__humanoidrootpart__i.CFrame)
	v1:TranslateBy(Vector3.new(5, 5, 5))
	task.wait(5)
	v1:Destroy()
	v3 = false
end

function fireTrioBeam()
	v4 = true
	v2 = i__GasterTestMulti__i:Clone()
	v2.Parent = workspace
	v2:SetPrimaryPartCFrame(i__humanoidrootpart__i.CFrame)
	v2:TranslateBy(Vector3.new(5, 5, 5))
	task.wait(5)
	v2:Destroy()
	v4 = false
end

while true do
	if v3 == false then
		fireBeam()
	if v4 == false then
		fireTrioBeam()
		end
	end
end

You can’t clone an array and may I have a look at your hiearchy?

1 Like

image
image
2nd image is workspace I have a button to spawn the boss, It then spawns in the GasterTest and deletes it. Ignore the “Gaster tester”

Try this:

local v2 = game:GetService('ServerStorage'):WaitForChild('GasterTest1'):GetChildren()

Attempt to call a nil value means that you are trying to get children on an object that does not exist.