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

How would I individually rename the children of a part?

Asked by
Chronomad 180
8 years ago

I'm trying to rename 13 motors so that I can further script them to make a custom character. How would I change the names one by one, descending the list of children?

local Body = script.Parent
    Body.PrimaryPart = Body.HumanoidRootPart

    for i=1, 13 do 
        local M = Instance.new("Motor6D") 
        M.Parent = Body.Chest
    end

        local Z = Body.Chest:GetChildren() 

1 answer

Log in to vote
4
Answered by
Azmidium 388 Moderation Voter
8 years ago

To give each motor a unique name, you must do this:

local Body = script.Parent
    Body.PrimaryPart = Body.HumanoidRootPart

    for i=1, 13 do 
        local M = Instance.new("Motor6D") 
        M.Parent = Body.Chest
    M.Name = "Motor" .. i -- 'i' gets the number of loops
    end

        local Z = Body.Chest:GetChildren()

This script will return a Motor named Motor then whatever id in the loop it is.

For example on the sixth loop, the Motor will be named "Motor6"

Sincerely,

jmanrock123

P.S. I HOPE THIS HELPED <3

0
Thanks a lot :) Chronomad 180 — 8y
0
No Problem :) Azmidium 388 — 8y
Ad

Answer this question