Running my script causes this error: Script:7: attempt to index nil with 'GetChildren'

As a learning scripter, I’m sure i’m doing something wrong which can be fixed in a jiffy. Thats why i’ve turned to you guys, the DevForum!

This is my script:

-- Defining who is who and what is what
local Issues = script.Parent.Parent:FindFirstChild("Issues")--Gets the Issues folder
local IssueBearers = script.Parent.Parent:FindFirstChild("IssueBearer")-- Gets the IssueBearers folder.

-- Due to using script.parent:FindFirstChild("Issues"):GetChildren() returning an error, i'll instead do the stuff below!

local IssuesChildren = Issues:GetChildren()

local CurrentIssue = script.Parent.Parent:FindFirstChild("CurrentIssue")
local IssueBearerImage = script.Parent.Parent:FindFirstChild("IssuBearer")

script.Parent.MouseButton1Click:Connect(function()
	
	local Ran = Random.new()
	local IssueNow = IssuesChildren[Ran:NextInteger(1, #IssuesChildren)]
	local BearerNow = IssueBearers[Ran:NextInteger(1, #IssueBearers)]
	
	print(IssueNow)
	print(BearerNow)
	
	
end)

The local Issues and IssueBearers are two folders inside of a GUI in StarterGui.image

I was trying to randomize the issues and the people who brought those issues to you. And when this code is run, this is the error i get:image

I’m quite confused by this error, so any help would be wonderful!
Thanks :smiley:

I spotted it. The reason why it’s nil is because your :FindFirstChild() call isn’t returning anything, because you’ve made a minor typo in its name. ‘Issu’ should be ‘Issue’ I’m presuming.

Whats causing the error is on line 7, which is Issues:GetChildren(). As far as i’m aware,

local IssuesChildren = Issues:GetChildren() 

does have children due to it being the name of the folder.

The typo down the line was intentional, since there is the name of the folder called IssueBearer, and the name of the button, which to differentiate from the folder was called IssuBearer.

image

Its a script inside of a button, supposed to randomize the ‘Issues’ when clicked.

I don’t understand how that would work, since there are multiple values inside of the Folder which i am referencing. Thats why i used GetChildren().

There doesn’t seem to be WaitForChildren()

So it doesn’t come up with an outright error, which is good, but instead gives me Infinite yield possible on ‘Players.coolkidtris.PlayerGui.randomize button:WaitForChild(“Issues”)’

It exists inside of the PlayerGui:
image

It does not seem like it.

(30chars)

Since this is client code, your script should be a LocalScript.

1 Like

i switched it to a localscript now, and its still either giving the error, or when changed to be WaitForChild, it still returns Infinite yield possible on ‘Players.coolkidtris.PlayerGui.randomize button:WaitForChild(“Issues”)’ when the button is clicked.

Can you screenshot the exact output?

image

changing all to WaitForChild() changes nothing

image Thats the output. followed by the Infinite yield is possible

Try doing this

for _,v in pairs(script.Parent.Parent:GetChildren()) do print("'"..v.Name.."'") end

to check for spaces, and screenshot the output

yes…

(((30characters))))))))))

image

There’s a space after the “s”, the last letter, in Issues.
Go into the explorer tab, and change the name of Issues from "Issues " to “Issues”

1 Like

Aaah well, silly me. I guess i checked wrong then. Although, after doing that, the script outputs this error: image

i know that the original question of this topic has been solved, but if you know how to fix this too, it’ll prevent me from creating another post.

this should be

local BearerNow = IssueBearers[Ran:NextInteger(1, #IssueBearers:GetChildren())]

Thanks a bunch! all of you! :smiley:

1 Like