Hi, So I'm currently a bit confused with DataStores, and I'm trying to specifically get them to save a string variable (called 'Value') that is located in game.Workspace. I have so far created a script that should save the player's data on exit (which I will share below) however, after looking through the ROBLOX Wikia and many other places I haven't found anything that will load data.
Here is the code I created to save player data
local DataStore = game:GetService("DataStoreService"):GetDataStore("Cash") game.Players.PlayerRemoving:connect(function(player) local key = "user_" .. player.userId DataStore:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 newValue = newValue + game.Workspace.Value.Value return newValue end) end)
Thanks for any help you can give me.
While data persistence is depresiated, I recomend it for a data save solution for people who are new to scripting.
To save data:
game.Players.PLAYER:SaveString("DATATITLE", "DATA CONTENTS")
To load data:
local DATA = game.Players.PLAYER:LoadString("DATATITLE"))
However, if you would like to remain with data stores, I recormend this guide by @ScriptGuider
https://scriptinghelpers.org/questions/25774/simple-datastore-introduction
I hope this helps!