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

Why wont this "repeat wait() until" script work? It seems like its a basic script that should...

Asked by
Dr_Doge 100
9 years ago

repeat wait() until script.Parent.Box == nil game.Workspace.Next = true

It keeps saying that Box dose't Exist in the Console. Thats the whole point of the script doe.... Dose soemone have a fix?

Heres a link to The error Report/Game Play

https://gyazo.com/0285679becd61d55682805aa738ed19e

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Asking for a child that's not there does not given you nil, it raises an error.

If you aren't sure something is going to be there, you have to ask with :FindFirstChild("Box"), which will return nil instead of erroring.

Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You're looking for Box, but you're already assuming it exists when you write

script.Parent.Box

If Box doesn't exist, it won't even get to the part that compares it to nil.

This is because before any comparison is made, the code first has to verify each side of the condition. If you try to access a nil value, it'll throw an error.


Use FindFirstChild. It's in a function form, so instead of erroring if the child doesn't exist, it will just return nil. This is valid.

repeat wait() until script.Parent:FindFirstChild("Box") == nil

Answer this question