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

Default value in DataStore2 possible [?]

Asked by 3 years ago

Since last time I gave my huge code so it made it harder for some people to help I made 15 line same concept code I Don't know how to set there default value, do you got any idea?

    local Rep = game:GetService("ReplicatedStorage")
    local DataStore2 = require(Rep:WaitForChild("MainModule"))
    DataStore2.Combine("Data","Money")
    local DefaultMoney = 5
    game.Players.PlayerAdded:Connect(function(Plr)
        local MoneyStore = DataStore2("Money",Plr)
        local Stats2 = Instance.new("IntValue", Plr)
        Stats2.Name = "leaderstats"
        local Money = Instance.new("IntValue", Stats2)
        Money.Name = "Money"
    local function MoneyUpd(GetData)
            Money.Value = MoneyStore:Get(DefaultMoney)
        end
        MoneyUpd()
        MoneyStore:OnUpdate(MoneyUpd)
    end)
0
You could set a metatable and use the .__index event which fires when an index of a table is indexed and is nil, and return the default value you want. User#32819 0 — 3y

Answer this question