Anyoneknow how to edit all children in a model using a script?

Anyone know how to edit all children in a model using a script?

  • btw here’s the path…

game.Players.player.Backpack:children
-also this “player” figure is from ProximityPrompt.Triggered:Connect(function(player)

1 Like

Well take this as example:

local tbl = {}
local player = game:GetService("Players").LocalPlayer

for i,v in pairs(player.Backpack:GetChildren()) do --loops through all childrens
table.insert(tbl,v.Name) --insert name of the children to table with name tbl. 
end

print(tbl)

:sweat: sorry for being such a noob but what if I was searching for the part “Handle1” and changing it to the name “Handle” inside the children.

Oh dont worry, we are started somewhere!

local tbl = {}
local player = game:GetService("Players").LocalPlayer

for i,v in pairs(player.Backpack:GetDescendants()) do --loops through all Descendants
if v.Name == "Handle1" then --check if the name is equal to Handle1 
v.Name = "Handle" --changing the name of Handle1 to Handle
end
end

Server Script Example:

local Model = game.Workspace.Model

for i,v in pairs(Model:GetChildren()) do
  
end

After the “do” line, and before the “end” line, place whatever code you want inside. (v = something inside the Model.)

for i,v in pairs() do is basically an advanced loop. Generally, this is used to iterate over a table, or I also use it to iterate over members of an Instance by using :GetChildren() , ‘i’ being the index of a table, and ‘v’ being the value of the index. In this case, ‘v’ will be equal to something inside the Model.

Please note that the thing about pairs is that there is no predictable order it will iterate over, much unlike ipairs which iterates over arrays in a chronological order.

@smowish012 If you want to do something specifically, then please tell me.

1 Like

So basically i have a system where the player has tools but i disabled there use because i changed the name of the Handle to “Handle1” so i want to make it so when script is executed itll take a look at all of the tools inside the player, and then it’ll change to name of all the handles inside all of the tools back to “Handle”

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player) 
for i,v in pairs(player.Backpack:GetDescendants()) do --loops through all Descendants
     if v.Name == "Handle1" then --check if the name is equal to Handle1 
          v.Name = "Handle" --changing the name of Handle1 to Handle
          end
     end
end) 

This should work in server script.

Server Script:

local ProximityPrompt = choose

ProximityPrompt.Triggered:Connect(function(Player)
    local Backpack = Player:WaitForChild([[Backpack]])

    for index, value in pairs(Backpack:Descendants()) do
       if value:IsA([[BasePart]]) and value.Name == [[Handle1]] and value.Parent.Name == [[ClassicTrowel]] then
         value.Name = [[Handle]] 
       end
   end
end)

Is that what you wanted?

@caviarbro @DevCramp I wanna thank you for sticking with me even though I’m prob being annoying but here’s a picture of the thing that needs to be changed:
snippet

-in the blue is where i want the rename to happen
also if you can make it so the script can be executable in a proximity thing like this:

ProximityPrompt.Triggered:Connect(function(Player)

You want it to change that handle name inside that specific tool? Or all tools?

if you can then please do all tools

-btw sry roblox’s 30 letter cap was getting in the way

Make this script a Server Script. It makes every tool, with a name “Handle1” change it’s name back to “Handle”:

Server Script
local ProximityPrompt = choose

ProximityPrompt.Triggered:Connect(function(Player)
local Backpack = Player:WaitForChild([[Backpack]])

   for index, value in pairs(Backpack:GetDescendants()) do
      if value:IsA([[BasePart]]) and value.Name == [[Handle1]] then
        value.Name = [[Handle]] 
      end
   end
end)

i got this message in the output:

snippet

Did you do it liek this?

thing:GetDescendants()

:upside_down_face: now I can finnaly sleep, also thanks for putting up with me :sweat: