Doc Bug? game:WaitForChild("Terrain") results in infinite yield

Hi folks, I’m a bit new to roblox so I’m getting tripped up on documentation that seems incorrect or out of date.

For example:

I’m running into an error here,

It has example code, game:WaitForChild(“Terrain”) but when I execute it I get

print(game:WaitForChild(“Terrain”))
02:28:25.416 - Infinite yield possible on ‘Place3:WaitForChild(“Terrain”)’

Should this be workspace:WaitForChild(“Terrain”) …

what is the difference between the two?

You need to be using workspace:WaitForChild(“Terrain”). Terrain is a child of workspace, and thus calling game:WaitForChild(“Terrain”) will infinitely yield because terrain will not be a direct child of game, it is a descendant of game.

5 Likes

game is referencing your place. And the children of the place are the different services. workspace is a child of the game. And the terrain is located in the workspace

Terrain is a member of workspace, all you need to do is:
local Workspace = game:GetService("Workspace") --//gotta say consistent! local Terrain = Workspace.Terrain or Workspace:WaitForChild("Terrain")

Also you were trying to literally print the Terrain! That won’t work, the print, warn & error functions only print strings.

Hope it helps and have a good one :+1:

2 Likes

Use of WaitForChild on Terrain is unnecessary especially if its from the server. Not only will the Terrain object exist on the server already, but it is also a property of the Workspace referencing the Terrain object. Don’t spend time waiting where you don’t have to.

Not quite sure what “doc bug” is, but what you might be thinking of here is incorrect documentation. If you’ve found a case where documentation is incorrect or otherwise providing inaccurate information, submit a request for Platform Feedback > Developer Hub regarding it.

2 Likes
local Workspace = game:GetService("Workspace") 

This code is not needed. You can just use the built-in workspace constant

local Terrain = workspace:WaitForChild("Terrain")

The workspace variable shouldn’t be used, it’s pretty bad practise.

Why is it bad practice to use workspace?

5 Likes

Actually I take that back! Turns out it’s faster to use workspace rather than doing game.Workspace, oh well!

I’m pretty sure it’s faster because it doesn’t have to index the DataModel.

Maybe the Lua VM fixed that, I’m not sure. Need to read up later on.

1 Like

doc bug = bug in documentation.

https://www.google.com/search?q="doc+bug"&rlz=1C1CHBF_enCA877CA877&oq="doc+bug"&aqs=chrome..69i57j0l7.1475j0j9&sourceid=chrome&ie=UTF-8

You mean a typographical error?

Thanks all.

1 Like

In this case, as Cinema said, it’d be a typographical error rather than a documentation bug. I don’t think those exist in the first place. The search term you placed doesn’t use “doc bug” to refer to documentation issues, never heard of that term being used.

@Cinema_Sin Difference in access between GetService, the property and the global is negligible.

2 Likes

As this conversation doesn’t seem to relevant to scripting, I’ll just agree to disagree here. Thanks for your technical assistance.

Terrain is a Child of Workspace, so you will need to do:

game.Workspace:WaitForChild('Terrain')