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

Why won't my map regeneration script repeat?

So i'm making a game with houses that regenerate once destroyed, the first regeneration works perfectly but dose not repeat itself after that.

Here's my code:

object = game.Workspace.Map
if (object ~= nil) and (object ~= game.Workspace) then 
model = object 
messageText = "Regenerating Map"

message = Instance.new("Message") 
message.Text = messageText 
backup = model:clone() -- backup model
waitTime = 3 -- How long it takes until new regen
wait(math.random(0, waitTime))

while true do 
	
wait(waitTime) -- Regen wait time 

message.Parent = game.Workspace 
model:remove() 

wait(3) -- how long the regen msg stays

message:Destroy()

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

I hope there's a simple solution to this :)

9 comments

1

:remove() isn't a thing and :Remove() is depricated.

0

Should i replace them with :Destroy()?

0

it still does the same thing, the map is not regenerating more than one time.

0

No it does not.

0

:remove and :Remove only set an object's Parent to nil, and Destroy does the same, but also locks the parent property (it cannot be reparent es unlike :remove), and prepares the object for garbage collection. :This article here explains this: https://scriptinghelpers.org/blog/do-you-have-zombies-in-your-code

0

wait, game.Workspace.Map is a folder filled with models. dose this change anything?

0

Change :remove() to :Destroy() and :clone() to :Clone()

0

Ok, ill try

0

It dose the first part of the proccess by 'destroying' the map, but the regeneration message just stays and the map dose not come back.

1 answer

function Regen()   --Whenever Regen() is activated it will start function
	object = game.Workspace.Map
if (object ~= nil) and (object ~= game.Workspace) then 
model = object 
messageText = "Regenerating Map"

message = Instance.new("Message") 
message.Text = messageText 
backup = model:clone() -- backup model
waitTime = 3 -- How long it takes until new regen
wait(math.random(0, waitTime))

while true do 

wait(waitTime) -- Regen wait time 

message.Parent = game.Workspace 
model:remove() 

wait(3) -- how long the regen msg stays

message:Destroy()

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

repeat   --Always checks to see when to start Regen()
	wait()
	object = game.Workspace.Map
	if (object ~= nil) and (object ~= game.Workspace) then 
		Regen()
	else
		wait(15)
		print("Game in Progress")
	end
until script.Name == "BAD" --If the script name becomes BAD then script will stop checking when to start regen


1 comment

0

The script works but still only regens the map once, are you sure it's finished?

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