Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you make this regen unanchor the model?

Trying to make this so it unanchors the vehicle so it doesn't mess up the welds. But how would I do so?

script.Parent.Parent.Name = "CarRegen"
local everything = {}
local names = {}
local children = game.ServerStorage:children()
local debounce = false

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 regen()
	for i = 1,#everything do
		local new_thing = everything[i]:clone()
		new_thing.Parent = game.Workspace.CarRegen
		new_thing:makeJoints()
	end
end

script.Parent.ClickDetector.MouseClick:connect(function(p)
	if not debounce then
		regen()
	end
end)

1 answer

✓ 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 -- true = changes colors; false = doesn't change colors.
local NameOfPartsToColor = "ChangeColor" --This is where the name of the parts you want to change colors goes.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.