Suphi's DataStore Module

I’m new to coding…

Is there any way to save data temporary?

so after player exit/reset character, the value will be reset.
I have tried example on “DEVELOPER PRODUCTS EXAMPLE” section but everytime I run the variable always increment.

for example:
datastore.Value.Inventory["Key 1"] = 1 --this variable always increment

I tried it On Roblox Studio…

How should I delete playerData completely?
In the process of development, I often delete and clean player data.
But this module cannot delete player data, even though used module’s Remove method and set value nil.
I also tried to delete in RunMode, but some old data coming back.
Does this module work in this situation?

-- if we are in studio stop the datastore from saving
if game:GetService("RunService"):IsStudio() then
	datastore.SaveInterval = 0
	datastore.SaveOnClose = false
end
1 Like
if datastore.State == true then
    datastore.Value = nil
else
    warn("Datastore is not open we cannot delete the data at this time")
end
1 Like

If I have used SDM, Do I need to record purchase history as seen on reference below (line 39 - 56):

...
success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end

	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId

	local success, isPurchaseRecorded = pcall(function()
		return purchaseHistoryStore:UpdateAsync(playerProductKey, function(alreadyPurchased)
			if alreadyPurchased then
				return true
			end
...

And What’s really purpose to record purchase history of developer product?

reference: MarketplaceService | Documentation - Roblox Creator Hub
(ProcessReceipt Callback code example / bottom part)

what I think is happening is
if you return Enum.ProductPurchaseDecision.PurchaseGranted its might not be 100% that this response will reach Roblox. if this happens Roblox might ask you to process a purchase more then once even if you returned Enum.ProductPurchaseDecision.PurchaseGranted

if your not worried about giving a player the same item more then once in this small edge case then you don’t need to record it but if you don’t want to give them the item more then once then you would need to record it just to make sure

1 Like

I think using local DataStoreModule = require(11671168253) frequently making my Roblox Studio freeze, as seen in below screenshot:

so, I need to click play - stop and play again until my game load…
Any solution to this?

Thank You in advance…

Insert the module and require it instead of the id

Thank You, now it solved! :+1:

What’s the best way to add a cleanup task?
I want to have some logic (potentially) set the data right before the player leaves (session destroyed).

it would be best to use the saving event to update data

but the even better option is to set the data as soon as it changes

2 Likes

Issue is that I want it to act on player leave.

For example: if they leave while in-combat make them lose their saved inventory.

1 Like

can you not do it on the player removing event before you call the destroy function?

1 Like

Yes, but will destroy not prevent saving?
Or does that try to perform a last save automatically?

1 Like

destroy will automatically save one last time before closing

3 Likes

So I have a question regarding using Datastore:Open() and Datastore:Read(), which returns to things, a string and any.

First off, what are the possible things the string can be equal too? I know one of them is “Success”, but what else?

And then what exactly is the any?

Other than that I have no other questions, thanks!

1 Like

Success, Saved, Locked, State, Error


you can read about the any type here Type checking - Luau

image

the ? at the end of types indicates that it may also be nil

so
string? = string | nil
number? = number | nil
any? = any | nil

2 Likes

Quick question how do I clear a datastore with your module? Like remove its data

1 Like
dataStore.Value = nil

:muscle::watermelon::hammer::blush:

3 Likes

currently, I’m trying to migrate my project to use Rojo / Argon, in this migration I need to save project in .rbxl file everytime I change something in Roblox Studio.

The idea is I will need to run start build.rbxl from console. However, I get this error on SDM Plugin:

You must publish this place to the web to access DataStore. - Server - MainModule:98

Do you think that I need this support on Argon or SDM?

1 Like