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?
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
By using the sub
[string] method of the string library.
for i,v in pairs(script.Parent.Parts:GetChildren()) do if v.Name:sub(1,5) == "disco" then -- Insert disco code here end end