How to check for keyword in part name

I want to use string.find() to find the word “Poop” in a part / model’s name, but I am not sure how to use that in this situation as its not going through a string, rather through a .Touched function.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Poop" then
       --nonesense code here
    end
end)

Would I do something like this ?

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name.find("Poop") then
       --nonesense code here
    end
end)

Does it work or does it errors?
Have you tried to add print() statements?

I get an error saying

string is not a valid member of Model “Workspace.eggspIicit_Poop”

when I try it that way

Try converting the name into a StringValue and di that from there

isnt the name already a string actually ?

It should, but I don’t know why it’s not working, try converting it into a StringValue

wrong character

if hit.Parent.Name:find(“Poop”) then
–do stuff
end

1 Like

thank you im not sure how i didnt notice

if anyone else comes to this thread, you also need to add the first parameter of what your trying to find through

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name.find(hit.Parent.Name,"Poop") then

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