Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you filter search a name?

Asked by
Scaii_0 145
6 years ago

So, I have a script that puts a brick into the workspace. It names the brick after the player, e.g. 'Scaii_0'sOwnPart' or 'ROBLOX'sOwnPart'. But I have another script that needs to try find ANY part named like this.

so it goes something like this:

if part.name == "ANYTHINGHERE'sOwnPart"

But, I'm not sure on how to do this. How would I look if something was in a name and ingore the rest of the name?

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Since you're searching for 'OwnPart and the Name property is a string, you can use string manipulation:

http://wiki.roblox.com/index.php?title=Global_namespace/String_manipulation

I'd recommend something like:

if string.find(part.Name,"sOwnPart") ~= nil
Ad
Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

String patterns (or just plain matches) are GREAT, I tell you!

Make a search using Pairs, Next, or IPairs, then check if their name contains OwnPart.

Part.Name:match('%\'%S*') --escape character because I used apostrophes

for i, v in pairs(workspace:GetDescendants()) do
    if v.Name:match('%\'%S*') then
        --code here
    end
end

for i, v in pairs(workspace:GetDescendants()) do
    if v.Name:match('OwnPart') then
        --code here
    end
end

Answer this question