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

Why is this code that reads a textbox not working properly?

local players = game.Players
local rblxCode

game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
	rblxCode = plr.PlayerGui["rblx.basic"].Frame.TextBox.ContentText
	if rblxCode == 'Print("Hello, world!")' then
		print("Hello, world!")
	end
end)

How come this code would not work? When I join the game, it outputs the error: rblx.basic is not a valid member of PlayerGui "Players.pevdn.PlayerGui" Even though it definitely is. https://ibb.co/zFzc9YJ

1 answer

You're trying to index the ScreenGui when the player joins, and it probably doesn't exist at that point.

You should use :WaitForChild() to make sure it definitely exists first. For example:

local gui = plr.PlayerGui:WaitForChild('rblx.basic')

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