Argument 1 missing or nil

hello! i’m having issue in my script “Argument 1 missing or nil” i tried everything to fix it and looked at other people forums about this error but didnt find an solution

local Assets = workspace:FindFirstChild("Assets")
local Objects = Assets:FindFirstChild("Objects")
local Planets = Assets:FindFirstChild("Planets")
local SolarSystems = Assets:FindFirstChild("SolarSystems")

for i, v in pairs(Planets:GetDescendants()) do
	local SystemToSearchFirst = v:GetAttribute("SolarSystem")
	local SystemToSearch = SolarSystems:FindFirstChild(SystemToSearchFirst) -- Error is here
	if SystemToSearch:FindFirstChild("Planets") then
	v.Parent = SystemToSearch:FindFirstChild("Planets")
	else
	local PlanetsInstance = Instance.new("Folder")
	PlanetsInstance.Parent = SystemToSearch
	PlanetsInstance.Name = "Planets"
	v.Parent = PlanetsInstance
	end
end
1 Like

what line is the error from? can you explain

look carefully, i already said in script where is error

That error indicates that SystemToSerchFirst is not finding the attribute of v, or v does not have the attribute "SolarSystem". I would make sure that v has the attribute or that you’re spelling it correctly.

afsias
i think i did everything fine in names

SystemToSearchFirst is nil

You can fix this by either having an if statement e.g.

if not SystemToSearchFirst then return warn(v.Name, " does not have the attribute!") end

Another option is by setting it to a default value.

SystemToSearchFirst = v:GetAttribute("SolarSystem") or "DefaultValue"

Finally you can also combine both:

if not SystemToSearchFirst then 
   warn(v.Name " does not have an attribute!")
   SystemToSearchFirst = "DefaultValue"
end

You can replace the if statement with:

local PlanetsInstance = SystemToSearch:FindFirstChild("Planets") or Instance.new("Folder")
PlanetsInstance.Name = "Planets"
PlanetsInstance.Parent = SystemToSearch

v.Parent = PlanetsInstance

Also you can try debugging by printing v.

Also you’re using GetDescendants not GetChildren.
GetChildren get the children which actually have the Parents set to the folder.
GetDescendants include the children of children etc.

Thanks! that was 2nd trouble i was having

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