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

How do I make a script refer to something that has not been created yet?

Imagine 2 scripts. 1 script has a piece of code that simply creates a model into the workspace. I want the other script to refer to that model but when I type in game.Workspace.model that piece of code will come up with red underlining. How can I make this script refer to the model that is created via the other script?

Please note that in this example, there is nothing in the Workspace before running the game.

1 answer

✓ Accepted answer

The WaitForChild function can be used in situations like this:

http://wiki.roblox.com/index.php?title=API:Class/Instance/WaitForChild

You can use this when you know something already exists, or is about to exist.

local model = workspace:WaitForChild("model")

The script will continue immediately if workspace.model already exists, or it will yield the current thread until workspace.model exists.

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