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

Why won't my map regeneration script repeat?

Asked by 5 years ago

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

1
:remove() isn't a thing and :Remove() is depricated. greatneil80 2647 — 5y
0
Should i replace them with :Destroy()? mrfrank79 30 — 5y
0
it still does the same thing, the map is not regenerating more than one time. mrfrank79 30 — 5y
0
No it does not. User#19524 175 — 5y
View all comments (5 more)
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 User#19524 175 — 5y
0
wait, game.Workspace.Map is a folder filled with models. dose this change anything? mrfrank79 30 — 5y
0
Change :remove() to :Destroy() and :clone() to :Clone() LoganboyInCO 150 — 5y
0
Ok, ill try mrfrank79 30 — 5y
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. mrfrank79 30 — 5y

1 answer

Log in to vote
0
Answered by
markjac -11
5 years ago
Edited 5 years ago
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


0
The script works but still only regens the map once, are you sure it's finished? mrfrank79 30 — 5y
Ad

Answer this question