Any easily spotted problems with this code?


	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)

Is there any problems in this code? When I run the game, I get the output:
rblx.basic is not a valid member of PlayerGui "Players.pevdn.PlayerGui"
even though it is a member of Playergui, as seen is the attached photo.
image


The context of my problem is I am trying to make a extremely basic resemblance of Lua inside of ROBLOX as an exercise. So this script is meant to detect when a TextBox has the contents of "Print(“Hello, world!”) and then print “Hello, world!” to the output.

are you trying to make a console like system?

Kind of- its just a textbox and this script is trying to monitor it if there is a recognized command in it. such as “Print(“Hello, world!”)”. i would type it into the textbox and it would then print it to the output.

local textbox = --reference your textbox here.

textbox:GetPropertyChangedSignal("Text"):Connect(function()

if textbox.text == "Print(Hello world)" then

print("Hello world")

end

end)

so there is something called loadstring in ServerScriptService its like a property enable it then paste this

local players = game.Players
local rblxCode
 
game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
    rblxCode = plr.PlayerGui["rblx.basic"].Frame.TextBox
    rblxCode.FocusLost:Connect(function()
        local Result = loadstring(rblxCode.ContentText)
        Result()
    end)
end)

BEWARE: loadstring may get your game hacked if you want a console it would be better if you use the roblox default console by pressing F9

That should work.




Or if you want it to display anything in the textbox, then do this:

local textbox = --reference your textbox here.

textbox:GetPropertyChangedSignal("Text"):Connect(function()

print(textbox.text)

end

end)

You can simply use GetPropertyChangedSignal. OR :match to detect a word.

Using GetPropertyChangedSignal

local TextBox = --Your textbox

--This will fire each time your textbox has changed.
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
  if TextBox.text == "Hello world" then
    --do code
  end
end)

Using match

local TextBox = --Your textbox

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
  if TextBox.Text:match("Hello World") then
    --do code
  end
end)

Of course you could use while loops instead of GetPropertyChangedSignal if you prefer to.

I tried out your code, and it now looks like this

local TextBox = game.StarterGui["rblx.basic"].Frame.TextBox

	TextBox:GetPropertyChangedSignal("Text"):Connect(function()
		if TextBox.Text:match("Hello World") then
			print("Hello world")
	end
	end)

It still does not print “Hello world” to the output- did I make a grammatical mistake?

Thanks for all your responses, but I am afraid that it is still not working properly. As you can see in the first attached image, the text " Print(“Hello world”) " is in the the “console” and it has not printed the text to the output.


In the second image see the code I am using.

You should try adding a :WaitForChild() for the rblx.basic object. Objects replicate to the client at different times, and based on the error you got the script is simply running before the GUI is added to the PlayerGui.

I changed my code to look like your description, and while the error is removed, “Hello world” is still not sent to the output. Edited code:

local TextBox = game.StarterGui:WaitForChild("rblx.basic").Frame.TextBox

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	if TextBox.Text:match("Hello World") then
		print("Hello world")
	end
end)

Try this:

local textbox = --reference your textbox

	textbox:GetPropertyChangedSignal("Text"):Connect(function()

		print(textbox.text)

	end)

This line.

local TextBox = game.StarterGui:WaitForChild(“rblx.basic”).Frame.TextBox

StarterGui is basically like a placeholder, it’s not the object that the client sees in production. Your original code should work, if you add the :WaitForChild() to it.

If you where talking about the code I had at the very start of the post, it would look like this.

local players = game.Players
local rblxCode

game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
	rblxCode = plr.PlayerGui:WaitForChild("rblx.basic").Frame.TextBox.ContentText
	if rblxCode:match ("rblx.basic.say (hello world)") then
		print("hello world")
	end
end)

I truly don’t know why it dosent work… Can you see any errors in this code?

local textbox = game.StarterGui:WaitForChild("rblx.basic").Frame.TextBox

	textbox:GetPropertyChangedSignal("Text"):Connect(function()

		print(textbox.text)

	end)

Still not working. I am extremely puzzled.

I think you are referencing the textbox incorrectly. Try putting the script Under the textbox and change this:

local textbox = game.StarterGui:WaitForChild("rblx.basic").Frame.TextBox

	textbox:GetPropertyChangedSignal("Text"):Connect(function()

		print(textbox.text)

	end)

to this:

local textbox = script.parent

	textbox:GetPropertyChangedSignal("Text"):Connect(function()

		print(textbox.text)

	end)

image

1 Like

This is a crazy fix. It is beyond simple yet so much time was spent trying to fix it.










It wasn’t in a LocalScript
image