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

My finding script has the wrong output I want it to have. Any help please?

Here's the code.

if game.Workspace.Model == nil then
	print("did not find the model")
elseif game.Workspace.Model then
	print("found the model")
end

The output says when I delete the model, > Model is not a valid member of workspace When if it isnt found I want it to print > did not find the model

Any help is greatly appreciated.

1 answer

✓ Accepted answer

When you do instance.Child while "Child" doesn't exist, it'll error. It thinks you're trying to get the property "Child" which doesn't exist, thus error with "Child is not a valid member". You need to use FindFirstChild:

if game.Workspace:FindFirstChild("Model") then
    print("found the model")
else
    print("did not find the model")
end

FindFirstChild returns the child you're looking for, unless it can't find it, then it returns nil.

1 comment

0

Just tested it. Thank you so much!

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