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

How do i fix my model regeneration script?

So i tried a script that regenerates models, but it just duplicates the model. Here is the script

model = script.Parent



backup = model:clone()

while true do
	wait(5) 

	model:Destroy()


	model = backup:clone()
	model.Parent = game.Workspace
	model:makeJoints()
	
end

Can i get help fixing it?

2 comments

0

If script.Parent is the model and you are using Destroy on the model. The script will also be removed.

0

Oh okay. I just tried moving the script into workspace and changing the top line to match my model's name. It works now.

1 answer

Version 1: Cloning (Duplication)

local model = script.Parent
local cframe = model.Primary.CFrame
local debris = game:GetService("Debris")

while true do
	debris:AddItem(model, 5.001)
	local backup = model:Clone()
	wait(5) 
	backup.Parent = workspace
	backup:SetPrimaryPartCFrame(cframe)
	backup:MakeJoints()
end

Using the Debris Service, we can remove the model after the clone is made.

Since we want it to appear where the first model was, we save the CFrame of the Model's PrimaryPart (make sure you have chosen one), then use :SetPrimaryPartCFrame() to move the model to that location.

Version 2: Model Movement (Specific Case)

Assuming your model would not be destroyed / altered in anyway, you can simply use the :SetPrimaryPartCFrame() to reset the model's position.

local model = script.Parent
local cframe = model.Primary.CFrame

while true do
	wait(5)
	model:SetPrimaryPartCFrame(cframe)
end

1 comment

0

This does not help the user at all and does not explain why their code is not working. Posting code and saying "use this or this" is noe helping. I could have easily posted 5 solutions for this task lol. -1

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