Hello I hope it doesnt sounds too confusing basically I’ve just recently started using string.lower and I want to find the lowered string in the table for example:
I want to find by “thisistring” - “ThIsiSsTring” inside the table.
You can use string.lower(string). Basically what this does is takes the string you plug into it and returns a lowered version of it. You can view more about strings here.
Example:
local My_Table = {thisisstring = 5} --Our table
local String = "ThIsiSsTring"
print(My_Table[string.lower(String)]) --Lower the string and print it
edit:
Just seen you said you started using string.lower() but I still hope this helps you.
The best way to accomplish this, is to lower A.) the thing you’re searching for or B.) the condition. It’s the easiest and most efficient way to lowercase one or both so that they match since Roblox is case sensitive.
Lanred_Dev is right then, you need to lowercase the thing you’re searching for, or at least the name. So for example, if I wanted to find a player based on UserInput…
for i, players in pairs(game.Players:GetChildren())
local playerName = string.lower(players.Name)
if playerName == string.lower(UserInput) then
print(players)
end
end
I am sure you can, but there’s no reason to? You can still print out the uppercase version while searching for it by the lowercase version. For example:
Let’s say there’s a guy named “BoB” in my server… I made a variable called lowerName…
lowerName = string.lower(playersInMyServer)
So now, BoB’s name is now bob.
You then would say, ok… does bob == bob? Yes, it does. So print BoB.
hmm… that’s effectively what the example I provided is doing but we can do it that way also.
Instead of lowering an input/string, we can lower both to get a match.
local My_Table = {ThIsiSsTring = 5} --Our table
local Input = "ThisiSStRinG" --Not the same as the table name
for Key, Value in next, My_Table do
if string.lower(Key) == string.lower(Input) then --Check if they are the same
print(Value) --Print the value
end
end
Okay so I am sending the data through RemoteFunction right so.
I will Invoke Server with
RemoteFunction:InvokeServer(TextBox.Text:lower())
And now I want to find out if the data is inside the table in server script.
RemoteFunction.OnServerInvoke = function(player, TextBox)
local mytable {"IamString"}
if mytable[(TextBox)] then
print("I am valid member of the table")
I get it now but how do I implement it to this code?
First issue, you’re missing an = on your mytable variable and it does not need to be inside the function as if you plan on having it add values you may not be able to access it and it will be reset every time the function/event is fired.
You’re also missing an end after your if statement and function, I am also assuming you have your RemoteFunction variable.
Now onto code.
local mytable = {"IamString"} --Table
RemoteFunction.OnServerInvoke = function(player, Text)
for _, Value in pairs(mytable) do
if string.lower(Value) == string.lower(Text) then --Check if they are the same
print("text is in table :)") --Print if they are the same
end
end
end
You should store the table variable outside the Remote Function invoke connection:
local RemoteFunction = game:GetService("ReplicatedStorage").PathToRemoteFunction
local myTable = {"IamString"}
RemoteFunction.OnServerInvoke = function(player, text)
for _, item in ipairs(myTable) do
if item:lower() == text then
return item
end
end
return nil
end