#Suphi's DataStore question

1 messages · Page 1 of 1 (latest)

coarse gyro
#

Are you sure you’re not somehow subtracting locally

severe horizon
#

No

#

Ill send the scripts

#
--DataStore main script
local DataStoreModule = require(game.ServerStorage.DataStore)
local playersService = game.Players

local template = {
    Coins = 0,
    Gems = 0,
}

local function StateChanged(state,dataStore)
    while dataStore.State ==  false do
        if dataStore:Open(template) ~= "Success" then task.wait(6) end
    end
end

playersService.PlayerAdded:Connect(function(player)
    local dataStore = DataStoreModule.new("Player",player.UserId)
    dataStore.StateChanged:Connect(StateChanged)
    StateChanged(dataStore.State,dataStore)
end)
playersService.PlayerRemoving:Connect(function(player)
    local dataStore = DataStoreModule.find("Player",player.UserId)
    if dataStore ~= nil then dataStore:Destroy() end
end)
#
--dev products
local DataStoreModule = require(game.ServerStorage.DataStore)
local marketService = game:GetService("MarketplaceService")
local playersService = game.Players
local DataStoreModule = require(game.ServerStorage.DataStore)


local products = {
    [1561337432] = function(receiptInfo)
        local dataStore = DataStoreModule.find("Player",receiptInfo.PlayerId)
        if dataStore == nil then return Enum.ProductPurchaseDecision.NotProcessedYet end
        if dataStore.State ~= true then return Enum.ProductPurchaseDecision.NotProcessedYet end
        dataStore.Value.Gems += 1000
        if dataStore:Save() == "Save" then
            dataStore.Leaderstats.Gems.Value = dataStore.Value.Gems
            return Enum.ProductPurchaseDecision.PurchaseGranted
        else
            dataStore.Leaderstats.Gems.Value -= 1000
            return Enum.ProductPurchaseDecision.NotProcessedYet
        end
    end,
}
marketService.ProcessReceipt = function(receiptInfo)
    return products[receiptInfo.ProductId](receiptInfo)
end
blazing lion
# severe horizon ```lua --dev products local DataStoreModule = require(game.ServerStorage.DataSto...

This code is not the same as how I showed in my video

  1. Your requiring the module twice for no reason local DataStoreModule = require(game.ServerStorage.DataStore)

  2. Your doing Save not Saved if dataStore:Save() == "Save" then should be if dataStore:Save() == "Saved" then

  3. Your subtracting from the leaderstats you should be subtracting from the data store dataStore.Leaderstats.Gems.Value -= 1000 should be dataStore.Value.Gems -= 1000

If you go back to my video and double check your code you will see that it's not the same

#

The playerdata script looks fine

#

The dev products has 3 problems

severe horizon
#

oh

#

thank you

blazing lion
severe horizon
#

Great module btw, is it possible to store stuff like 'hats' or anything like this alongside the currency stats?

blazing lion
severe horizon
#

Nice.

severe horizon
#

A quick question related to donations, so I know now to handle the products, but when it comes to the top donors board itself, it uses GetOrderedDataStore()
is it okay to use both that for the board and store the donations themselves in the player data?

blazing lion
#

i think it might be better to just save it in the OrderedDataStore

#

and dont save it in the playerdata

#

you can if you want to but then you have to make sure they both stay in sync

#

that should not be to hard so its kinda upto you