Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i fix my model regeneration script?

Asked by 5 years ago

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?

0
If script.Parent is the model and you are using Destroy on the model. The script will also be removed. User#5423 17 — 5y
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. CxldMoon 0 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago

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
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 User#5423 17 — 5y
Ad

Answer this question