#Suphi's DataStore question
1 messages · Page 1 of 1 (latest)
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
This code is not the same as how I showed in my video
-
Your requiring the module twice for no reason
local DataStoreModule = require(game.ServerStorage.DataStore) -
Your doing Save not Saved
if dataStore:Save() == "Save" thenshould beif dataStore:Save() == "Saved" then -
Your subtracting from the leaderstats you should be subtracting from the data store
dataStore.Leaderstats.Gems.Value -= 1000should bedataStore.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
no problem 🙂
Great module btw, is it possible to store stuff like 'hats' or anything like this alongside the currency stats?
sure thing you can store strings numbers booleans and tables for example you can do
local template = {
Coins = 0,
Gems = 0,
Hats = { -- the player will start with 2 hats
"NoobHat",
"ProHat",
}
EquippedHat = "NoobHat" -- the player has the NoobHat equipped by default
}
Nice.
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?