Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the console say Position isn't a valid member of Script?

So it works the first time but when it tries to do the second loop it comes up with this error: "Position is not a valid member of Script". This is my code:

under = workspace.under

for name, child in pairs(under:GetChildren()) do
	if child.Position.Y < workspace.Baseplate.Position.Y then
		print("c")
	end
end

1 comment

1

Probably beacause the second child the in pairs function checked is a Script. What you can do is instead of an in pairs loop, use an in ipairs loop to iterate over the "under's" childs in a sequence. Then if you have like 32 parts, models, or whatever you want to iterate over, you set the loop to break in 1 more index value. Like with 32 parts it breaks when it reaches the index value of 33.

2 answers

✓ Accepted answer

The most likely answer is that you have a script inside of your "under" object.

It would be in your best interest to ensure that the "child" in question is a BasePart. You can either do this manually by filtering out all of the instances that aren't Parts, or you can use some logic like

if child:IsA("BasePart") then

Either way should resolve the issue at hand.

Yes you can just say like:

if child.ClassName == "Part" or "Model" or "Union" or "Mesh" then
      if child.Position.Y < workspace.Baseplate.Position.Y then
	        print("c")
      end
end

2 comments

0

Downvoted because this will not work and lack of explanation.

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.