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

Problems with Regening a model, help?

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 :)

2 comments

0

And no, it didn't say anything in the output, hmm...

0

It happens to me all the time so I want to solve this problem once and for all, please help ;D

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks that really helped!

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