Hello! I recently wanted to add a Christmas update to my game, and I wanted to make all the trees white, but the game is realistic and has over 2,000+ trees, so I didn’t want to spend 20 years changing them all white, so I decided to make a script that will do it for me. I realized that I never named the log or leaves so they both are the same, so I tried to make the script change the TextureID of a mesh that has a certain TextureID. However, the script won’t work. Now, I suck at scraping and both my scripters are asleep so I came here for help!
Script: (In ServerScriptService)
game.Players.PlayerAdded:Connect(function()
if game.Workspace.Trees.Model.MeshPart.TextureID == "rbxassetid://739625341" then
game.Workspace.Trees.Model.MeshPart.TextureID = "rbxassetid://4493097869"
end
end)
What it wants to change: (One of the MeshParts has the certain one, I am trying to change every one in ever single tree model at once)
for _, v in pairs(game.Workspace.Trees:GetChildren()) do
for _, part in pairs(v:GetChildren()) do
if part:IsA("MeshPart") then
if part.TextureID == "rbxassetid://739625341" then
part.TextureID = "rbxassetid://4493097869"
end
end
end
end
You have to loop through the instances in folder. But make sure that there are only trees that have the same structure!
local treeFolder = workspace:WaitForChild("Trees")
local trees = treeFolder:GetChildren()
for _, tree in ipairs(trees) do
for _, part in ipairs(tree) do
if part:IsA("MeshPart") then
if part.TextureID == "rbxassetid://739625341" then
part.TextureID = "rbxassetid://4493097869"
end
end
end
end
Iterating over arrays is faster with the iterator function “ipairs()”, you also don’t need this inside a PlayerAdded event unless you want it to execute each time a new player is added, it only needs to execute once when the server is first created, if you want this to be a permanent change you can execute the code from the command bar.