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

LocalScript: can't find script's children?

I was making a GUI using a normal script but for various reasons I had to change it for a localscript. After the change, this first part of the code works on roblox studio, but doesn't work online:

ZINDEX = script.Parent.Parent.ZIndex.Value
script.Message.ZIndex = ZINDEX -- it breaks at this line because it can't find script.Message

"Message" is a frame which is a children of the localscript, but when I try it online it says that "Message" is not a part of the localscript

Does anyone have any idea on why this happens? Thank you

1 answer

✓ Accepted answer

When dealing with the local player, it's common practice to use WaitForChild whenever accessing descendants of the player.

ZINDEX = script.Parent.Parent.ZIndex.Value
script:WaitForChild('Message').ZIndex = ZINDEX -- it breaks at this line because it can't find script.Message

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