Question about using string.find on stringValues

The title basically is the entire question. Is there a way to use the string.find command to check a stringValue inside the workspace? I’ve used the command to check the names of certain objects but nothing I’ve done works with finding the value of a stringValue.

It’s as simple as doing

 local str = workspace.StringValue.Value
 print(str)

String.find isn’t needed here unless you need to get the position of an occurence within a string.

StringValue.Value is the string the object contained, use it as you use strings.

1 Like

You can get the value of a stringValue by doing object.Value, then doing whatever you want to do with it, this page may be helpful.
Or this
Or this
Example:

local strVal = workspace.stringValue.Value
local whattofind = "ello"
string.find(strVal, whattofind)

I need to check if the value has certain letters but since the player can slot the letters in any order I wanted to use string.find to just check for individual letters instead of an exact value.

The code below would check if the value of a has the letter b right?

local a = hit.Parent.Type.Value
string.find(a,"b")

Oh oops I didn’t even see this post okay so I was doing it right thanks. Thanks for the links too btw I just get confused reading the dev hub sometimes.

You’ll need an if statement to see whether a match was found first,

 local str = "abc"
 if str:match("b") then print("found") end -- valid

 -- or
 if string.find(str, "b") then print("found") end -- valid

 -- setting the plain flag to true causes it to find the literal pattern instead of a Lua pattern
 local str = "a[bc"
 if str:find("[",1,true) then print("found") end

You could even check like this

 local str = "abc"
 local found = string.find(str, "b") ~=  nil -- will be true in this case
 -- to not get indices, but just whether a pattern was found
 -- returns either true or false
2 Likes

Thanks for the detailed response!

1 Like