Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if the name of a part starts with a certain phrase?

I am making a disco floor and in the disco floor's code I am doing this:

for i,v in pairs(script.Parent.Parts:GetChildren()) do
	if v.Name == "discoPart" then
		-- Insert disco code here
	end
end

I want to make my disco floor more sophisticated, but not put a script in every block, so how do I check if the part name starts with disco but then it doesn't matter what else follows?

2 answers

✓ Accepted answer

Use string.sub like so.

for i, v in pairs(script,Parent.Parts:GetChildren()) do
	if string.sub(v.Name, 1, 5) == 'disco' then
		--insert stuff here
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.