hello !
in this script, you can see that it does some thing with finding/getting, then it changes a color.
i was wondering if i could also make it rename “Chest2” when it changes the color at the same time?
script.Parent.Touched:Connect(function(hit)
local Mesh = hit.Parent:FindFirstChild('Chest2') --thing i want to rename
if Mesh then
for i, v in pairs(Mesh:GetChildren()) do
if v.Name == "1" and v:IsA("BasePart") then
v.Color = Color3.new(0.831373, 0.831373, 0.831373) -- it changing color
end
end
end
end)
for some reason this didnt work its still named Chest2
the updated script
script.Parent.Touched:Connect(function(hit)
local Mesh = hit.Parent:FindFirstChild('Chest2')
if Mesh then
for i, v in pairs(Mesh:GetChildren()) do
if v.Name == "1" and v:IsA("BasePart") then
v.Color = Color3.new(0.831373, 0.831373, 0.831373)
v.Name = "Item"
end
end
end
end)
Obviously Chest2’s name isn’t 1, you’re renaming a part named “1” to “Item”, plus you’re not renaming the Chest, you’re renaming a child of the chest (based on your code). If you want to rename the chest, do
script.Parent.Touched:Connect(function(hit)
local Mesh = hit.Parent:FindFirstChild('Chest2')
Mesh.Name = ""
if Mesh then
for i, v in pairs(Mesh:GetChildren()) do --Mesh's children
if v.Name == "1" and v:IsA("BasePart") then
v.Color = Color3.new(0.831373, 0.831373, 0.831373)
v.Name = "Item" --Referring to child, not Chest2
end
end
end
end)
script.Parent.Touched:Connect(function(hit)
local Mesh = hit.Parent:FindFirstChild('Chest2') --thing i want to rename
if Mesh then
for i, v in pairs(Mesh:GetChildren()) do
if v.Name == "1" and v:IsA("BasePart") then
v.Color = Color3.new(0.831373, 0.831373, 0.831373) -- it changing color
v.Parent.Name = "Chest1"
end
end
end
end)
I’ve added a single line of code which will change the name of “Chest2” if the color of one of its children is changed.
Remember to reference it by its new name if you plan on adding code which executes after the name has been changed.