#Suphi's DataStore Module

1 messages · Page 2 of 1

covert crescent
#

if its success then I can't remember what it returns

#

yer that's right it will give you the id of the lock

solar tulip
#

I recreated it just now

covert crescent
#

yes you just delete the memory store

covert crescent
solar tulip
#

uhh what

covert crescent
#

I don't know what that warning is

solar tulip
#

It closed the normal and time datastore

covert crescent
solar tulip
solar tulip
#

getTimeDatastore should yield until the session is open

covert crescent
#

but these errors are not related to are problem

solar tulip
covert crescent
#

can you try something

solar tulip
covert crescent
#

well can you try this idea I have

solar tulip
covert crescent
#

once you enter the game

open the data store like you normally do

then after like let's say 10-20 destroy the datastore

but stay in the game don't exit

and see of the data store reopens

solar tulip
covert crescent
#

put a print so you know the data store is trying to open again

solar tulip
covert crescent
#

also you don't need to deep copy template SDM does that for you

covert crescent
#

really you should just have 1 per player

solar tulip
#

mb

covert crescent
#

can you try the thing I said

solar tulip
#

alright

#

1sec

covert crescent
#

in wondering if something is reopening the data stores after its been destroyed

solar tulip
#

should i do it ingame

#

@covert crescent

#

was it the statechaned that opened my data again?

#

it couldn't be

#

right?

covert crescent
#

I don't know how you did it

solar tulip
#

did what

covert crescent
#

is the server opening the session again after you destroy it

solar tulip
#

ignore them

solar tulip
#

let me do it again more clearly

#

the first 3 are from when I join the server

covert crescent
#

why does it say locked?

solar tulip
#

look at the timestamps

solar tulip
covert crescent
#

ok

#

sooo what I think is happening is not that we need the task.wait in bind to close

#

is when you teleport a player it instantly trys to reopen

#

there data store and then locks them out

solar tulip
#

wait I forgot to disable my timestep function that gets called every second

#

lemme disable it and retry

covert crescent
#

ok

#

but still

#

even without the time step

#

you should only be opening the data store if the player enters the server or there data store is closed not destroyed

solar tulip
#

You're right

covert crescent
#

so let's look at your code where when the state changes it opens the datastore again

solar tulip
#

I think I found the issue

#

the timestep called every second so if it gets called after BindToClose gets fired then the function would reopen the datastore

#

hence locking the session

covert crescent
#

but your code should not even try to open the session if the data store does not exist

#

only when the player enters or if the state becomes closed

#

but never if the state is destroyed or it can't find the data store

#

but I think that my bindtoclose function should protect you from opening the session after it tries to close but I can't remember

solar tulip
#

this should hopefully fix it?

#

the false tells the function not to open the datastore if it couldn't find it using datastore.find

covert crescent
#

see how there is active = false

solar tulip
#

yes

covert crescent
#

I think that is supposed to stop you from opening new datastores

solar tulip
covert crescent
#

but maybe its not 100% safe

#

maybe if you start opening just before active is set to false it might bypass it

#

butt

#

if you do what I said

#

then you don't even need active

solar tulip
#

I do that though

covert crescent
#

so the rules are
1 only open the datastore if the player entered the game
2 only open the datastore if the state is closed

solar tulip
#

I open the datastore on playerjoin and then use .find whenever i need to access the datastore

#

it broke again even after I added a failsafe to timestep

covert crescent
#

looks like your still opening it after you destroy it when you should not be doing that

solar tulip
#

let me check which part of the code does that

covert crescent
#

if you do find and don't find it then you don't open it

#

if you open it after find that's not correct

#
ds = find(...)
if ds == nil then new() end

doing this is wrong

solar tulip
#

i'm doing

covert crescent
#

you should only call new inside player added no where else

#

also show me your state changed function maybe there is a problem there

#

also maybe when you do migrate update it does not call bind to close instantly ?

#

anyways let's see the state changed function that reopens your data store

solar tulip
#

i removed the deeopclone btw

solar tulip
#

Alright so the issue is fixed

For anyone having the same issue where the session does not get closed after you migrate to latest update or shutdown all servers, Check your scripts and see if anything opens the datastore again after player leaves it could be anything like a cash loop or a time loop that increments the player's time played every second

#

@covert crescent you should check the active thing again since it was letting me open the datastore even after bindtoclose had already fired

solar tulip
covert crescent
#

but its good the know there is not a fundamental problem with SDM but we must be careful not to open a datastore outside of a player entering the server

covert crescent
#

as long as you follow the rule
only call datastore.new inside player added and no where else then you should always be ok

solar tulip
covert crescent
#

outside of playeradded you can only use datastore.find

solar tulip
#

I tested > 50 times with shutdown all servers and migrate to latest update with 5 people and the bug did not occur again

covert crescent
#

good thats good news

#

its a simple rule should be easy not to forget

solar tulip
#

yeah

covert crescent
#

i might post it on the forum

solar tulip
#

thanks for the help though

covert crescent
#

np

#

im happy you solved it

solar tulip
#

:D

covert crescent
#

forum has been updated

glass plaza
#

@covert crescent how would i make a leaderboard with this since i cant do getorderdereddata

covert crescent
glass plaza
#

oh alright my bad

#

is it this

covert crescent
#

yup

glass plaza
#

tysm

sullen nexus
#

are the datastores accessible across the experience or place level only?

covert crescent
sharp cedar
#

does the module still work fine even with the recent changes to datastores?

covert crescent
sharp cedar
covert crescent
sharp cedar
#

oh okay thats great

#

thank you

oblique crown
#

does this module have safety features to ensure that players do not get locked out of their data for a week if MemoryStoreService goes down like it did today?

covert crescent
mighty rose
#

how do i wait for dataStore.Value to exist without stopping the entire function? do I use pcalls or repeat until true
-# this is my first time using this module and im new to scripting btw

local RESPAWN_DELAY = 3

local function onPlayerAdded(player)
    
    local function onCharacterAdded(character)
        local humanoid = character:WaitForChild("Humanoid")

        local function onDied()
            task.wait(RESPAWN_DELAY)
            player:LoadCharacterAsync()
        end

        humanoid.Died:Connect(onDied)
    end

    player.CharacterAdded:Connect(onCharacterAdded)

    player:LoadCharacterAsync()
    -- i want player to spawn at dataStore.Value.Stage but dataStore.Value ends up being nil
end

Players.PlayerAdded:Connect(onPlayerAdded)
royal tulip
#

You'd connect to datastore's StateChanged event

mighty rose
#

Would I do find(), new() or open()?

royal tulip
#

new

mighty rose
#

forgot to reply

mighty rose
#

What does dataStore:Set() do in the Signal example?

#

Also does ValueChanged fire for every data that changes in datastore? for example if I have Coins and Playtime, does it fire every time either one changes

mighty rose
#

and that also answers my other question

lean fiber
#

How can I manually destroy the datastore everytime PlayerRemoving is called?

shut peak
#

This automatically compresses dictionaries right?

#

Attempting to load data with this template but I am getting a "Cannot Store Dictionary error"

#

I couldve sword it formatted data like this

#

Might be unsupported types in Color3 lemme check

shut peak
#

Nvm then

#

Anyway if anyone knows the supported way for me to get the CompressedValue, please let me know.

#

I assume its wrote-to after the DataStore is closed or saved

covert crescent
covert crescent
shut peak
shut peak
covert crescent
#

It will be difficult to move to another module

shut peak
covert crescent
#

So only what roblox supports is supported

shut peak
#

Maybe I'm misinterpreting it

covert crescent
shut peak
#

Neat

torn meadow
#

Am I using the "find" function worng here? I supposed the third argument was to find a specific key inside the datastore, issue is this return nils, even tho the key I am trying to search for is correctly stored inside the player data store

#

oh wait yes, i remember, it's only to find datastore not key inside it

#

my bad