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

Problems with Regening a model, help?

Asked by 8 years ago

So here, everything goes well except the part where the script removes the old version of the model. So basically, it removes it the first time, but stops removing it all those other times. This script is in Workspace and is targeting a model called "Wall". Please help :)

-- Made by Alucifer

-- Variables:

model = game.Workspace.Wall
children = model:GetChildren()
backup = model:Clone()

message = Instance.new("Message")
message.Text = "Regenerating "..model.Name.."..."

-- The function:

function regen()
    print("Begin function")
    -- show the message

    message.Parent = game.Workspace
    wait(2.5)
    print("Showing message...")

    -- remove the current model

    model:Destroy() -- PROBLEM: only does this once, doesn't do it all those other times...
    print("Old model has been destroyed!")

    -- make a copy of the new one

    local newModel = backup:Clone()
    newModel.Parent = game.Workspace
    print("New model has been placed!")

    wait(1)
    message.Parent = nil
    print("Hiding message...", "End of function")
end

-- The while loop

while wait(15) do
    regen()
end


-- end of script :D

I would be very thankful if you could help. Thank you for your time :)

0
And no, it didn't say anything in the output, hmm... Alucifer 45 — 8y
0
It happens to me all the time so I want to solve this problem once and for all, please help ;D Alucifer 45 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago

After destroying model for the first time model isn't defined (It's nil), you can't remove nothing so you needed to redefine what model is so it's not nil. Here's the script:

-- Made by Alucifer

-- Variables:

model = game.Workspace.Wall
--children = model:GetChildren() -- You don't use this line, seems a bit pointless.
backup = model:Clone()

message = Instance.new("Message")
message.Text = "Regenerating "..model.Name.."..."

-- The function:

function regen()
    print("Begin function")
    -- show the message

    message.Parent = game.Workspace
    wait(2.5)
    print("Showing message...")

    -- remove the current model

    model:Destroy() -- PROBLEM: only does this once, doesn't do it all those other times...
    print("Old model has been destroyed!")

    -- make a copy of the new one - REDEFINED WHAT model IS

    model = backup:Clone()
    model.Parent = game.Workspace
    print("New model has been placed!")

    wait(1)
    message.Parent = nil
    print("Hiding message...", "End of function")
end

-- The while loop

while wait(15) do
    regen()
end


-- end of script :D

Hope this works the way you wanted, if it does please like and accept as answer. If it didn't meet what you required please comment/message me and I'll edit it ASAP.

0
Thanks that really helped! Alucifer 45 — 8y
Ad

Answer this question