Trouble editing a UI when the script first runs


I am looking to edit the existing chat GUI. I do not want to create a custom one, I simply want to remove parts, and move them. Here is my code:

local player = game.Players.LocalPlayer

local function OnChatLoad()
	local chat = player.PlayerGui.Chat:WaitForChild()
	local ChatPos = chat.Frame.Position
	chat.Frame.Position =, ChatPos.X.Offset, 0.715, ChatPos.Y.Offset)


The issue is that the script errors. The error given is:

  23:51:40.737  Chat is not a valid member of PlayerGui "Players.Jay3721.PlayerGui"  -  Client  -  Move Chat:4

I have tried adding a one second wait via wait(). That is pretty “clunky” and not well optimized, so I’d love to be able to take advantage of an event or something of that nature to run the function to edit the chat so that I know the “Chat” UI is loaded before running it.


local chat = player.PlayerGui.Chat:WaitForChild()
local chat = player.PlayerGui:WaitForChild("Chat")


You haven’t specified “Chat”.

local Chat = player.PlayerGui:WaitForChild(“Chat”)

Thanks, That works! After having read your response it’s obvious to me that what you said works, and what I initially did doesn’t, for some reason when I was reading through the documentation on the developer hub, I got the idea that what I did was the correct way of waiting for something to load.