Hello! So I have the following script:
local children = script.Parent:GetChildren()
-- Clearing not needed crap inside the PlayerGui instance
local cutscenegui = script.Parent:WaitForChild("Cutscene")
cutscenegui:FindFirstChild("SkipCutscene").MouseButton1Click:Connect(function()
for i = 1, #children do
if script.Parent:FindFirstChild(children[i]).ClassName == "LocalScript" or script.Parent:FindFirstChild(children[i]).ClassName == "Folder" then table.remove(children, i) end
end
for i = 1, #children do
script.Parent:FindFirstChild(children[i]).Enabled = true
end
end)
I am getting the following error:
Players.Kostiskat.PlayerGui.LocalScript:8: attempt to index nil with 'ClassName'
(line 8)
Help would be appreciated!
It is calling a number on a child so it thinks it is this:
part1
Change this
To this
:FindFirstChild(children[i].Name)
Since you are searching with an instance and not a name
2 Likes
Also it was trying to call the child with a number
No. Its getting a member from a table using [number]
1 Like
I have gotten an error like this before. I believe it is because the Instance you are trying to find doesn’t not have a class name because it probably doesn’t exist. I would recommend putting a:
print(script.Parent:FindFirstChild(children[i]))
right before that line and see what it prints in the output.
Maybe try :WaitForChild(). If there is a warning then it doesnt work
Also i would recommend to use :IsA() instead
This
if script.Parent:FindFirstChild(children[i].Name):IsA("LocalScript")
is the same as
if script.Parent:FindFirstChild(children[i].Name).ClassName == "LocalScript"
Thats because you are searching it using an instance. Not a string
Try this instead
print(script.Parent:FindFirstChild(children[i].Name))
Okay, it prints the class names properly too, but it return nil for folder instances. Would :IsA do the upposite?
I don’t know how you would implement it since :IsA() is only using for if statements and stuff
Ok so that basically means that nothing the table is getting actually exists or something is causing whatever was there to disappear. I would recommend trying what [zaydoudou] suggested but it might not work because if the instance doesn’t exist, how could it have a name?
It is getting it from the table. Its just finding the child through an instance and not through a string
Turns out there’s actually another problem, since there are Roblox core instances created inside the player gui.
