#datastore code not working

1 messages · Page 1 of 1 (latest)

rough jolt
#
local datastoreModule = require(game.ServerStorage.DataStore)

local datastore = datastoreModule.new("Player", "CharacterModel", "Good")

datastore.StateChanged:Connect(function(state, dataStore)
    print(dataStore.Id, state)    
end)

datastore.Saving:Connect(function(value, dataStore)
    print(dataStore.Id, value)
end)

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


datastore:Open(template)

if datastore:Open(template) ~= "Success" then error("Datastore failed to open") end

print(datastore.Value)

datastore.Value.Coins += 1

datastore:Destroy()
#

prints an error, that i cant add smth to nil, or add one to a number

#

more cleaner version of the code:

boreal mauve
#

The code you're showing is not even 36 lines long

rough jolt
#

yeah

boreal mauve
#

Where's the error located?

rough jolt
#

thats the comments

#

line with datastore valuec oins

#

i can show the other error, made two scripts without comments so its easier

boreal mauve
#

datastore.Value.Coins is nil

rough jolt
#

although, i did open it to the template

#

with the value coins

hidden valve
#

Set the value to nil and try again

rough jolt
#

alrigh

hidden valve
#

If you still have hello world set template won't overwrite hello world

boreal mauve
#

I'm actually impressed you figured that out from so little information

rough jolt
#

it printed out a table ID, most likely reffering to the template table