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

How to take a sum of values in a table to set an attrribute?

Asked by 1 year ago

I'm aware the title is very confusing (as it is for me), but to give you relevant context, I'm currently creating a RTS game that is similar to Rise of Nations. In this game, cities have a set population with an already added population growth mechanic I want the city's population to accumulate towards their host nation's population as a sum.

while wait(5) do
    local Cities = workspace.Cities --Defines the Cities
    for _, v in pairs(Cities:GetChildren()) do -- Run cpde for every city in the Cities folder.
        local cityPop = v:GetAttribute("Population") -- Defines population of the city
        local Owner = v:GetAttribute("Owner") --Defines the owner of the city (host nation)
        local OwnerPart = game.Workspace.Countries[Owner] --Sets the tangible country of the city
        local growth = cityPop*0.01 --growth rate
        v:SetAttribute("Population", cityPop + growth) --simulates growth
        if Owner == OwnerPart.Name then --If the owner string = the Ownerpart.name then..
            --??, dont know what to put after that.
        end
    end
end

Answer this question