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()
#datastore code not working
1 messages · Page 1 of 1 (latest)
prints an error, that i cant add smth to nil, or add one to a number
more cleaner version of the code:
The code you're showing is not even 36 lines long
yeah
Where's the error located?
thats the comments
line with datastore valuec oins
i can show the other error, made two scripts without comments so its easier
datastore.Value.Coins is nil
This is most likely that you already have data inside and so the template is not getting added
Set the value to nil and try again
alrigh
If you still have hello world set template won't overwrite hello world
I'm actually impressed you figured that out from so little information
it printed out a table ID, most likely reffering to the template table