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

Help! How to give parts with certain properties names, automatically?

Asked by 6 years ago

So in workspace, If any object is a really red ball I want it to be named "Lock On!". How would I be able to do that?

I tried making the script below but it didn't work! Help!

--This is in a LocalScript
game:GetService('RunService'):Connect(function()
for _, child in pairs(game.workspace:GetChildren()) do
    if child.ClassName == 'Part' and child.BrickColor == "Really red" then
       child.Name = "Lock on!"
    end
end
end)

0
1. Are you sure that the part you're looking for is already in the workspace? And 2. Is it parented directly under workspace, or under something else that's in workspace? XAXA 1569 — 6y
0
Also, try using child:IsA("Part") instead, and change "Really Red" into BrickColor.new("Really red") XAXA 1569 — 6y
0
Lastly, and this might be the cause. but you're connecting to RunService directly, not to something like Stepped or RenderStepped. XAXA 1569 — 6y
0
That is inefficient to just check that every FRAME. Not like you need to check this 60 times a second, 3,600 times a minute. Also, how hard is this for you guys to indent properly? hiimgoodpack 2009 — 6y
View all comments (3 more)
0
Also, if you are going to instance a ball (assuming you did not insert it in studio and just like NOT RENAME IT), why cant u just rename the part while making it? Does not make sense. hiimgoodpack 2009 — 6y
0
@himmgoodpack The point of the script is to give names to parts of those properties automatically. Without naming it in Studio. JoeRaptor 72 — 6y
0
Why? This makes lag for things that is preventable if YOU JUST NAMED THEM IN STUDIO. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

This script should work for you. You need to use IsA instead of using ClassName and using RunService will spam Lock On.

for i,c in pairs(game.Workspace:GetChildren()) do
        if c:IsA("Part") then --Use "IsA" instead
               if c.BrickColor == "Really red" then
                     print("Lock On")
end 
end
end

I'm on mobile so I apologize for poor indentation. Please accept my answer if this helped!

0
Remember to remind him to not check 60 times a second, 3,600 times a minute. hiimgoodpack 2009 — 6y
0
@hiimgoodpack One would say RenderStepped is a no brainer, cause it keeps things smooth JoeRaptor 72 — 6y
1
You should use DescendantAdded or ChildAdded. hiimgoodpack 2009 — 6y
0
Agreed^^, GetChildren() scales poorly if there are thousands of parts in workspace. Just do GetDesendants() once. If the part you're looking for isn't in GetDescendants(), then listen to DescendantAdded. XAXA 1569 — 6y
Ad

Answer this question