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

GetChildren() can't find model thats in workspace?

Although there is a model within workspace with the name Boat1 this script doesn't identify that it exists for some reason? Any idea of what could be causing this?

function Search()
local X = model:GetChildren()
  for i = 1, #X do 
Print("WorksUpToHere")
	if X.ClassName== "Model" and X.Name == "Boat1" or X.Name == "Boat2" or X.Name == "Boat3" then

      if (X.PrimaryPart.Position-t.Position).magnitude <= 29 then
	
	workspace.Sspawn.BrickColor = BrickColor.new("Really black")
clicker.MaxActivationDistance=0
print("Here")
repeat wait() until(X.PrimaryPart.Position-t.Position).magnitude >= 30
print("Over Here")
	game.workspace.Sspawn.BrickColor = BrickColor.new("Really red")
clicker.MaxActivationDistance=32  
end
end
end
end 

1 answer

X is a list of children, not an object. X.ClassName and X.Name are both nil since a list of things does not have a name nor class.

What you mean to write is to do something for each element in x. You should use a generic for loop for that:

for _, object in pairs(model:GetChildren()) do
	if object:IsA("Model") and (object.Name == "Boat1" or object.Name == "Boat2" or object.Name == "Boat3") then
		......

1 comment

0

Alternatively, you could go with a numeric for loop, like so: local children = model:GetChildren() for i = 0, #children do local child = children[i] print(child.Name, ":", child.ClassName) end. Though you should stick to a generic for loop as it is more straightforward.

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