Suphi's DataStore Module

I haven’t used any datastore modules in my life so I might as well learn this, but I don’t think that it will be worth learning this for people who already use profile service,

2 Likes

Discord is the worst for documentation.

3 Likes

How would I go about transferring from DataStore2 (considering I already have an active game using that module) to this?

Also I have another unrelated question if you don’t mind me asking, what if I don’t like a specific key name I set and would like to change it but perserve the data of that key

@5uphi

1 Like

So datastore2 saves the data in a different key for different players

One player might be on key 274745
Another player might be on key 32

So first you would use the ordered datastore to find out what key they are on then you would load that key then you would save that data into SDM

If you want to delete all 274745 keys of that player it’s going to take you a long time to do that you might just have to leave them all there


To change key using SDM all you do is open both keys set the value from one to the other then destroy them both

2 Likes

I tried using this module and it worked for the first time however when i tried creating another script with your module for some reason the my data did not want to save:

--Character Customization
local RigDataFolder = script.Parent.RigData -- A folder with bool values, string values etc
local DataStoreModule = require(game.ServerScriptService.Modules.DataStoreModule)

local Template = {
	SkinColour = Color3.new(0.6, 0.5, 0.4),
}

game.Players.PlayerAdded:Connect(function(player)
	local PlayerID = player.UserId

	local PlayersCustomization = DataStoreModule.new("Customization", "PlayerData", PlayerID)
	local Data = PlayersCustomization:Open(Template)

	if Data ~=  DataStoreModule.Response.Success then
		local Time = 1
		print("Data store failed to open")
		while PlayersCustomization.State == DataStoreModule.Response.Error do
			if PlayersCustomization:Open() ~= DataStoreModule.Response.Success then task.wait(Time) Time *= 2 end
		end
	end

	RigDataFolder:WaitForChild("SkinColour").Value = PlayersCustomization.Value.SkinColour
	
	script.Parent.LoadPlayerDataDone.Value = true
	PlayersCustomization:Destroy()
	
	PlayersCustomization = DataStoreModule.new("Customization", "PlayerData", PlayerID)
	Data = PlayersCustomization:Open()
	print(PlayersCustomization.Value)
end)

I’v added last 3 lines of code to test if it saved and in the output i get nil. Am i doing something wrong?

2 Likes

You can’t save a color3 into the datastore

Use ToHex

To convert your color3 to a string

Also state and response are not the same thing
So
PlayersCustomization.State == DataStoreModule.Response.Error will not work

It finally works. Thank you for help and for this module :grinning:

I get what you’re telling me but how would I do it like the keys can’t be just numbers they have to involve the player’s id somehow right? Also for changing key names I would have to keep that bit of code for replacing forever cuz of how many ppl have that old key name data?

What I would do :
Open suphi datastore player first , if it is empty I look for the datastore2 key,if empty then just set your started data on suphi datastore player or if it is not empty then apply that data to suphi datastore player.

here is a example of how to extract the latest data from datastore2

local dataStoreKey = dataStore2Name .. "/" .. player.UserId
local dataStore = dataStoreService:GetDataStore(dataStoreKey),
local orderedDataStore = dataStoreService:GetOrderedDataStore(dataStoreKey),

local mostRecentKey = orderedDataStore:GetSortedAsync(false, 1):GetCurrentPage()[1]
if mostRecentKey == nil then error("player does not have any player data inside datastore2") end
local playerData = dataStore:GetAsync(mostRecentKey)

-- if you wanted to remove all player data saved by datastore2 you would have to loop from 1 to mostRecentKey
-- WARNING mostRecentKey can be a very high number and this loop could take a very long time to finish
-- for i = 1, mostRecentKey do
--     orderedDataStore:RemoveAsync(i)
--     task.wait(6)
--     dataStore:RemoveAsync(i)
--     task.wait(6)
-- end

print(playerData)

don’t forget to use pcall as GetSortedAsync, GetAsync, RemoveAsync can all fail

3 Likes
MemoryStoreService: InternalError: Failed to parse MemoryStoreService JSON response. API: SortedMap.Update, Data Structure:

I am not using MemoryStoreService in any external scripts.
Platform: Mac OS | Roblox Studio

1 Like

Did you enable API calls in game settings under security?

MemoryStoreService: InternalError: Failed to parse MemoryStoreService JSON response - Bug Reports / Studio Bugs - Developer Forum | Roblox
seems like your note the problem

I don’t think that’s the same problem

Yes, I did enable API calls in game settings.

1 Like

Was there any more information from the error message?

1 Like

Working on a website version using moonwave stay tuned

3 Likes

It’s here. Still working on adding more docs and API. SuphisDataStoreModule | SuphisDataStoreModule

7 Likes

oh heck that’s amazing wow nice job

1 Like

Hey Suphi,
I’ve been loving your DataStore module and using it for a while for my game. Recently, one of my data save attempts only affected if I exit and enter the game. So, datastore saves but datastore.StateChanged event won’t trigger for this specific save attempt. This should trigger but it won’t untill I relog:

And this is where I update datastore:

Appreciate if you could help me.

1 Like