I have a for loop that loops through the descendants of a folder looking for a StringValue with the same string the player has typed in a textbox and if it finds a StringValue with the exact string as the player typed in, it makes a Frame called Bar inside the folder visible and the code works completely fine but I have an issue if the player were to type in a string that no StringValues have, nothing would happen but I want a text pop up saying that string doesn’t exist if it doesn’t find any StringValues with that string
I literally have no idea what solutions I can try since I have never in my entire life seen a code that does something like that, and I have tried googling and searching for a solution on DevForum but I couldn’t find any, so that’s why I’m asking this since this project is really fun and I don’t want something like that to ruin everything for me
Here’s the code:
local Process = {}
function Process.StartProcess()
for i,v in pairs(script.Parent.Folder:GetDescendants()) do
if v.Name == "Value" then
if v.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Monitor.SurfaceGui.MonitorFrame.TopBar.CurrentString.Value then
v:FindFirstChild("Bar").Visible = true
end
end
end
end
return Process
No, there’s no error happening, the code works completely fine but I want it to show a text saying that string doesn’t exist if it doesn’t find a StringValue with the string the player has typed in the textbox
This should work… I hope.
For what you’re trying to achieve.
local Process = {}
function Process.StartProcess()
for i,v in pairs(script.Parent.Folder:GetDescendants()) do
if v.Name == "Value" then
if v.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Monitor.SurfaceGui.MonitorFrame.TopBar.CurrentString.Value then
v:FindFirstChild("Bar").Visible = true
else
--Code goes here
end
end
end
end
return Process
local Process = {}
function Process.StartProcess()
local matchedString = false
for i,v in pairs(script.Parent.Folder:GetDescendants()) do
if v.Name == "Value" then
if v.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Monitor.SurfaceGui.MonitorFrame.TopBar.CurrentString.Value then
v:FindFirstChild("Bar").Visible = true
matchedString = true
end
end
end
if not matchedString then
print("Text doesn’t exist. Tell the user")
end
end
return Process
Then just change the text in the if statement that has the print that says Text doesn’t exist.Tell the user
Since I can’t mark both your post and CloudYugen’s post as a solution I instead liked your post and say thank you, since I don’t want to hurt your feelings because I’m someone that doesn’t want to hurt other people’s feelings
I marked CloudYugen’s post as a solution since he was first
but you still had a good solution
I hope you have an amazing day!
Wait one second before you go I just want to make sure you’re aware of something. The code @SuguruDev provided works however I chose not to do it this way for 1 main reason that I’m not sure if you’re aware about or you just don’t care.
But when you type a word, and then loop through all the TextValues if the first text value doesn’t match that word then the text will display even if it matches a later value so users might see a “flash” of the words which could be annoying, but it’s your choice