TextBox Input Checker is NOT WORKING!

What’s my Goal?

I want to make the TextBox Input Checker Script to check if the user’s input is equal to “Hi” (Example)

What’s the Problem?

local Input = game.StarterGui.ScreenGui.Screen.Input
local Submit = game.StarterGui.ScreenGui.Screen.Submit

Submit.MouseButton1Click:Connect(function()
	local Input_Lower = string.lower(tostring(Input.Text))
	if Input_Lower == "hi" or Input_Lower:find("hi") then
		print("It worked")
	end
end)

I’ve tried this script but, it doesn’t seem to work! (The script is errorless)
Can anyone find the problem with the script and suggest a solution? :thinking:

Here’s a Video

Question Answer - Roblox Studio 2022-03-22 12-45-39

tHAT’S STARTERGUI not PlayerGui.

oops caps

I’m sorry, I don’t understand… Can you please explain it in more detail?

Above is correct, just want to explain why here so you can get a better understanding.

You’re referencing StarterGui, which isn’t the Players actual GUI. StarterGui is like a container, it gets replicated to PlayerGui whenever they join.

Assuming this script is in the actual UI, you could simply do:

local Input = script.Parent.PathToTheInput
local Submit = script.Parent.PathToTheButton

But because we don’t know where that’s located, you could also do

local Input = game.Players.LocalPlayer.PlayerGui.ScreenGui.Screen.Input
local Submit = game.Players.LocalPlayer.PlayerGui.ScreenGui.Screen.Submit
3 Likes

You need to use parent-based indexing on Ui elements, or any service which clones its descendants into the player.

The StarterGui is one of those services whose contents are cloned into the PlayerGui. What you really have to access is the PlayerGui, so change your script to this:

local gui = script.Parent
local Input = gui.Screen.Input
local Submit = gui.Screen.Submit

Submit.MouseButton1Click:Connect(function()
	local Input_Lower = string.lower(tostring(Input.Text))
	if Input_Lower == "hi" or Input_Lower:find("hi") then
		print("It worked")
	end
end)
2 Likes

When the game runs, the instances from StarterGui gets moved to each player’s PlayerGui. An Ideal solution to this would be using script.Parent. So, your script should be:

local GUI = script.Parent
local Input = GUI.Screen.Input
local Submit = GUI.Screen.Submit

Submit.MouseButton1Click:Connect(function()
	local Input_Lower = string.lower(tostring(Input.Text))
	if Input_Lower == "hi" or Input_Lower:find("hi") then
		print("It worked")
	end
end)

[Sorry, didn’t mean to reply to you specifically.]

Don’t know why you replied to me :man_shrugging:

It worked! Thanks, @alphadoggy111. That was a silly mistake from my side… :sweat_smile:

1 Like