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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

Ad

Answer this question