✓ Accepted answer
I don't know if this will completely work, I think it will.
script.Parent.Parent.Name = "CarRegen"
local everything = {}
local names = {}
local children = game.ServerStorage:children()
local debounce = false
local ChangeColor = true
local NameOfPartsToColor = "ChangeColor"
for i = 1,#children do
if (children[i].Name == "Car") then
table.insert(everything, children[i]:clone())
table.insert(names, children[i].Name)
end
end
function unanchor(Model)
local ThingsToUnanchor = Model:GetChildren()
for i = 1, #ThingsToUnanchor do
if (ThingsToUnanchor[i]:IsA("Part")) then
ThingsToUnanchor[i].Anchored = false
elseif (ThingsToUnanchor[i]:IsA("Model")) then
local TTU = ThingsToUnanchor[i]:GetChildren()
for i = 1, #TTU do
if (TTU[i]:IsA("Part")) then
TTU[i].Anchored = false
end
end
end
end
end
function ColorCar(Model)
if ChangeColor then
local ThingsToColor = Model:GetChildren()
local Color = BrickColor.random()
for i = 1, #ThingsToColor do
if (ThingsToColor[i].Name == NameOfPartsToColor) then
ThingsToColor[i].BrickColor = Color
end
end
end
end
function regen()
for i = 1,#everything do
local new_thing = everything[i]:clone()
new_thing.Parent = game.Workspace.CarRegen
new_thing:makeJoints()
unanchor(new_thing)
ColorCar(new_thing)
end
end
script.Parent.ClickDetector.MouseClick:connect(function()
if not debounce then
regen()
end
end)