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.
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.
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
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.
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.
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)
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?