02-03-2011, 11:05 PM
When something is exploded or otherwise destroyed, it isn't going to go back together! This can be a problem, and will be even more important once multiplayer is released. But don't worry, using Lua scripting (especially the clone() function) you can backup and restore anything you'd like!
First, you should add the parts you want to backup to a model (Buildism's way of grouping similar items.) This can be accomplished by using the Group button in the toolbar.
Once you have your model, rename it to give it a more descriptive name: select it in the navigator, then change the Name property in the properties panel (lower left corner.)
If you want to make a rebuild button, make a box (preferably fixed and noncollidable) and insert a script into it. To insert a script, select the box then click Edit>Insert Object, select Script, and click OK.
Double click the script to edit it, then copy and paste the following code:
With some modifications, you can use the same kind of script to make a model rebuild every few minutes, or when a player types something in the chat box.
First, you should add the parts you want to backup to a model (Buildism's way of grouping similar items.) This can be accomplished by using the Group button in the toolbar.
Once you have your model, rename it to give it a more descriptive name: select it in the navigator, then change the Name property in the properties panel (lower left corner.)
If you want to make a rebuild button, make a box (preferably fixed and noncollidable) and insert a script into it. To insert a script, select the box then click Edit>Insert Object, select Script, and click OK.
Double click the script to edit it, then copy and paste the following code:
Code:
model = game.World.YourModelName --Path to the model
message = "Rebuilding..." --Message to show while rebuilding
backup = model:clone() --Make a backup
enabled = true
link(script.Parent.Clicked, function(player, btn) --Called when the box is clicked
if not enabled then return end
enabled = false
script.Parent.Color = Color(127, 127, 127)
local copy = backup:clone() --Make a copy of the backup
model:remove() --Remove original
game:message(message)
sleep(2) --Wait for 2 seconds
game.TaskScheduler:schedule(function() --Using TaskScheduler ensures that nothing moves in the middle of the script
copy.Parent = game.World --Add the copy we created to the world
copy:makeJoints() --Recreate any welds or hinges that were in the original
end)
model = copy --Change our variable to point to the new model
game:message() --Clear the message
sleep(3)
enabled = true --Make the button clickable again
script.Parent.Color = Color(0, 102, 255)
end)
With some modifications, you can use the same kind of script to make a model rebuild every few minutes, or when a player types something in the chat box.