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

Data can't be stored in tables in DataStores2 like the normal method?? HELP!!!!

Asked by 4 years ago

So, I've added a part in workspace. Whenever that part is clicked, money value increases

Which part of this script should i edit so that the data is stored in a table?

local dataStore = require(1936396537) -- gGets Data Store 2

local startValue = 0 -- the value for new players

local function entered (plr) -- plr is the current player
    -- Gets the data about money (for that player)
    local moneyStore = dataStore("Money", plr)

    local function moneyUpdate(updatedValue)
        -- Money display in the leaderboards is set to the new and updated value (for moneyStore)
        plr:WaitForChild("leaderstats").Money.Value = moneyStore:Get(updatedValue)
    end

    moneyUpdate(startValue) -- When a player joins, their money value is 0

    moneyStore:OnUpdate(moneyUpdate) -- Everytime this value changes, money update is called

end

----------------------------------------------------------------------------------------------

local function clicked (plr)

    local moneyStore = dataStore("Money", plr)

    -- Adds a value to the moneyStore everytime this function is called
    moneyStore:Increment(50, startValue)

end
----------------------------------------------------------------------------------------------

game.Players.PlayerAdded:Connect(entered) -- When a player enteres a game

game.Workspace:WaitForChild("Part").ClickDetector.MouseClick:Connect(clicked) -- when that part is clicked

Answer this question