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

I need to pairs 2 tables in this workspace backup script, How do I do that ?

Asked by 4 years ago
print("Server backup by BrennoMaturino1 (I am from brazil)")

local ignore = {
    --Exemplo: workspace.Rocket --[[-- AQUI VÃO OS MODELOS QUE DEVERÃO SER IGNORADOS --]]--


    workspace.Lobby,
    workspace.GameScripts,
    workspace.Terrain
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
}
local instances = {} --Não mexa, aqui são armazenados os modelos do jogo com excessão os que devem ser ignorados

function PlayerJoined(player)
    player.CharacterAdded:Connect(function()
        if table.find(ignore, player.Character) == nil then
            table.insert(ignore, player.Character)
        else
            warn("O character do jogador: "..player.Name.." Foi adcionado mas já está na tabela")
        end
    end)
end

function ClearTable(tbl, IsInstance)
    if IsInstance == true then
        for number in pairs(tbl:GetChildren()) do
            table.remove(instances, number)
        end
    else
        for number in pairs(tbl) do
            table.remove(instances, number)
        end
    end
end

function CloneWorkspace()
    if table.getn(instances) ~= 0 then
        ClearTable(instances, false)
    end
    for number, instance in pairs(workspace:GetChildren()) do
        for number2, tableobj in pairs(ignore) do
            if instance ~= tableobj then
                local startclone = instance:Clone()
                local clone = nil
                if startclone then
                    local clone = startclone:Clone()
                end
                table.insert(instances, clone)
            end
        end
    end
end

function RestoreLastBackup()
    for number, instance in pairs(workspace:GetChildren()) do
        for number2, tableobj in pairs(ignore) do
            if instance ~= tableobj then
                instance:Destroy()
            end
        end
        for number, instance in pairs(instances) do
            instance.Parent = workspace
        end
    end
end


workspace.GameScripts.Events.MakeBackup.OnServerEvent:Connect(CloneWorkspace)
workspace.GameScripts.Events.RestoreBackup.OnServerEvent:Connect(RestoreLastBackup)

I need to pairs workspace while i pairs the ignore table The ignore table not is ignoring the models, i need to synchronize the workspace and the ignore table

0
Yes, I know it would be difficult to do like that way, but I don't know any better way. User#32819 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You don't need to loop both of these tables, just loop one and use if statements to see if it's on the ignore table using ignore[1] to identify the position of the table.

print("Server backup by BrennoMaturino1 (I am from brazil)")

local ignore = {
    --Exemplo: workspace.Rocket --[[-- AQUI VÃO OS MODELOS QUE DEVERÃO SER IGNORADOS --]]--


    workspace.Lobby,
    workspace.GameScripts,
    workspace.Terrain
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
    --workspace. --[[-- NOME DA INSTANCIA --]]--
}
local instances = {} --Não mexa, aqui são armazenados os modelos do jogo com excessão os que devem ser ignorados

function PlayerJoined(player)
    player.CharacterAdded:Connect(function()
        if table.find(ignore, player.Character) == nil then
            table.insert(ignore, player.Character)
        else
            warn("O character do jogador: "..player.Name.." Foi adcionado mas já está na tabela")
        end
    end)
end

function ClearTable(tbl, IsInstance)
    if IsInstance == true then
        for number in pairs(tbl:GetChildren()) do
            table.remove(instances, number)
        end
    else
        for number in pairs(tbl) do
            table.remove(instances, number)
        end
    end
end

function CloneWorkspace()
    if table.getn(instances) ~= 0 then
        ClearTable(instances, false)
    end
    for number, instance in pairs(workspace:GetChildren()) do
        for number2, tableobj in pairs(ignore) do
            if instance ~= tableobj then
                local startclone = instance:Clone()
                local clone = nil
                if startclone then
                    local clone = startclone:Clone()
                end
                table.insert(instances, clone)
            end
        end
    end
end

function RestoreLastBackup()
    for number, instance in pairs(workspace:GetChildren()) do
    if instance ~= ignore[1] or instance ~= ignore[2] or instance ~= ignore[3] then
                instance:Destroy()
           else
            instance.Parent = workspace
        end
    end
end


workspace.GameScripts.Events.MakeBackup.OnServerEvent:Connect(CloneWorkspace)
workspace.GameScripts.Events.RestoreBackup.OnServerEvent:Connect(RestoreLastBackup)

I hope this helped you!

0
Thanks for the reply and sorry for the delay, but I don't like doing it the way you did, because if I have a very large table, I will need a very large IF if and if I need to use a table.insert () as I will make this ? [Sorry for english mistakes, I am from Brazil] BrennoMaturino1 10 — 4y
Ad

Answer this question