How do I make a script do something if it doesn't find a StringValue with the same string as a player as inputed

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

Do you mind telling me what line this error is happening on?
So I can have more knowledge of whats going on.

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

Oh alright, sorry I completely read that wrong.

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
1 Like

You could try this:

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

1 Like

OHHHH, How could I be so stupid, I must be really exhausted since I have got only like 3 hours of sleep three days in a row

1 Like

Lol, try to get some sleep. Hard work pays off.
You deserve the sleep.

1 Like

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!

1 Like

Thanks, I’ll try going to sleep earlier and take a little break from programming
I hope you also have a great day!

Sounds good, have an amazing day and if you need anymore help just let me know!

1 Like

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

1 Like

Oh, I didn’t know that, thank you for your telling me

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.