"x is not a valid member of folder y"

I have done lots of stuff like this and never have I encountered this problem before.

During the saving of playerdata, I am looping through the children of a folder. The folder has one objectvalue which links to a planet the player owns and the rest of the children are models of planets.

Here’s the portion of the datasaving script I’m having problems with:

for i,v in pairs(plrplanets:GetChildren()) do
		if v:IsA("Model") then
			plrplanetsitems[v.Name] = {
				["acidity"] = v:GetAttribute("acidity"),
				["age"] = v:GetAttribute("age"),
				["gravity"] = v:GetAttribute("gravity"),
				["groundpressure"] = v:GetAttribute("groundpressure"),
				["humidity"] = v:GetAttribute("humidity"),
				["materialdensity"] = v:GetAttribute("materialdensity"),
				["mined"] = v:GetAttribute("mined"),
				["radiation"] = v:GetAttribute("radiation"),
				["temperature"] = v:GetAttribute("temperature"),
			}
		else
			local addplanet = v
			
			plrplanets[addplanet.Value.Name] = { --error on this line
				["acidity"] = addplanet.Value:GetAttribute("acidity"),
				["age"] = addplanet.Value:GetAttribute("age"),
				["gravity"] = addplanet.Value:GetAttribute("gravity"),
				["groundpressure"] = addplanet.Value:GetAttribute("groundpressure"),
				["humidity"] = addplanet.Value:GetAttribute("humidity"),
				["materialdensity"] = addplanet.Value:GetAttribute("materialdensity"),
				["mined"] = addplanet.Value:GetAttribute("mined"),
				["radiation"] = addplanet.Value:GetAttribute("radiation"),
				["temperature"] = addplanet.Value:GetAttribute("temperature"),
			}
		end
	end

When looping through, I get an error (which the location is marked on my code) that reads

Planet of Player1 is not a valid member of Folder "Player1.Planets"

So what I’m getting from this is it is looping through the data, noticing an object value, getting the value of it and for some reason going “Hey, this area of workspace you’ve referenced from is not in this folder!” - WHO CARES? I specifically WANT you to reference that value! I don’t see why it should matter if it’s a child of the folder or not, just ADD IT!

I’ve never encountered this problem before. I use lots of these objectvalues in my game and frequently reference them in loops. I’ve restarted studio which has done nothing to help as from experience and from other posts have learnt that studio can be at fault. Appears not this time…

1 Like

If plrplanets is a reference to the “Player1.Planets” folder in the Roblox game, then attempting to index it with a string that doesn’t correspond to a child of that folder would cause an error.

Yeah… I just realized how embarrassing this is. Thank you very much nevertheless!

2 Likes

The error message mislead you a bit.

It doesn’t fail because it isn’t in the folder, but rather because the script cannot find the child of Player1.Planets with the name Planet of Player1, which is what plrplanets[addplanet.Value.Name] does. Replace plrplanets with the actual parent of the object.

2 Likes

I didn’t even notice someone replied while I was typing.

1 Like

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