Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Oeplion 15
7 years ago

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

Log in to vote
0
Answered by
einsteinK 145
7 years ago

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.

0
Just tested it. Thank you so much! Oeplion 15 — 7y
Ad

Answer this question