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