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

Cloning a model to workspace?

Asked by 7 years ago

I want to clone "Map2" from Lighting if it gets removed from Workspace. Here's my attempt which didn't work.

local map = "Map2"
local backup = "Map2"
local find = game.Lighting:FindFirstChild(backup)
local area = workspace
if game.Workspace:FindFirstChild(map) then
    print ("Map found")
elseif 
    (backup) then
    backup:Clone().Parent = area
end

2 answers

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

The problem with your code is that it is just going to run at the start of the server, and be done.

If you want this to be in effect constantly you should use the ChildRemoved event. This event fires whenever a descendant of the specified object is removed.

Note: Lighting isn't meant for storage, you should use ServerStorage.

Note[2]: There's no need to define the same thing twice.. line 2 is redundant

local map = "Map2"
local backup = game.ServerStorage:FindFirstChild(map)

workspace.ChildRemoved:connect(function(child)
    if workspace:FindFirstChild(map) then
        print ("Map found")
    else
        backup:Clone().Parent = workspace
    end
end)
Ad
Log in to vote
-1
Answered by
cabbler 1942 Moderation Voter
7 years ago

"backup" is just a string. "find" is the actual backup map. So you should do

elseif find then
    find:Clone().Parent = area
end

Next time check the output because I guarantee there are errors.

Answer this question