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

I'm trying to use a script to edit several other objects with the same names. How? (ANSWERED)

Asked by 9 years ago

THIS IS ANSWERED I dont know how to mark it as answered so yeah

So everything is in the model 'Stuff' and in that is 2 objects named 'Test' and a script in the model with them. How do I use the script to select both of the objects and edit BOTH of them.

Go to "sync.in/roblox" and I'll show my Tree (or what it looks like) I dont even have a script because I dont know how to make it, so that's all I can show you

I tried using FindFirstChild, but, as that is written, it only edits the 'First' Child it finds that matches its search. Please help. URGENT. Thanks! Please keep simple, I don't want to use a for script, that will be buggy with what I'm working on

I used to be able to do this, sorry for the stupid question.

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

The straightforward way is to find all children using :GetChildren(), and then ignore those without the the name you're looking for:

for _, child in pairs(parent:GetChildren()) do
    if child.Name == "WantedName" then
        -- Do whatever to `child`
    end
end

A less elegant approach would be to continually rename the objects:

local thing = parent:FindFirstChild("WantedName")
while thing do
    -- Do whatever to `thing`
    thing.Name = "UsedUpName"
    thing = parent:FindFirstChild("WantedName")
end

This is obviously less desirable since it changes all of the names of the children. Ideally, you would have an equivalent loop that puts them back. It makes more sense to just go over all of the children in the simple for loop.

0
What I need, though, is for all the children by 'Test' name to be edited at the SAME time. It can't be at different times or it ruins the game I'm trying to make, so, would both of these work? Jabbypappy 0 — 9y
0
Thanks, it works. I appreciate it Jabbypappy 0 — 9y
Ad

Answer this question