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

Is there a way to clone models from tables?

Asked by 4 years ago

Here is some example code of what I want to accomplish:

local sky = workspace.Sky:GetChildren()
local repStorage = game.ReplicatedStorage
local severeRisk = repStorage.SeverityRiskValue.Value

local cloudTable = {
repStorage.Cloud1, 
repStorage.Cloud2, 
repStorage.Cloud3}

while repStorage.EventReady.Value == true do
    for i, storm in pairs(sky) do
        local stormType = storm.StormType.Value

        local growChance = math.random((stormType * 6), 100)
        if growChance > severeRisk then
            local nextCloud = cloudTable{stormType + 1}
            local cloud2 = nextCloud:Clone()
            cloud2.Parent = storm.Cloud
        end
    end
end

This code does not work because cloning models from tables is not possible. Is there any other way I could attempt something like this?

1 answer

Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

i don't know where you got that idea from, because cloning models from tables is completely possible

tables are just storage devices for other values, the only restrictions on them are when you try to pass them through bindables or remotes, or save them in datastores

the problem is in this line right here

local nextCloud = cloudTable{stormType + 1}

you don't index tables with {}, you index them with [], so that line should be

local nextCloud = cloudTable[stormType + 1]
Ad

Answer this question