How do I save the values/string of a leaderboard stat and have it load the next time the player joins the game? The following is the script I will be using for my game:
game.Player.PlayerAdded:connect(plr) local leaderstats = Instance.new("Model",plr) leaderstats.Name = "leaderstats" local lvl = Instance.new("IntValue", leaderstats) lvl.Name = "LVL" lvl.Value = 1 local currency = Instance.new("IntValue", leaderstats) currency.Name = "Gold" currency.Value = 100 end)
I would like you to edit this script so that it could save and load the next time the player joins. I would also like you to elaborate the workings of saving and loading values (when I tried to check the roblox wiki, something about Data store came up but I don't really understand).
Heres to save, load data.. http://wiki.roblox.com/index.php?title=DataStore
This should teach you about saving / loading data. ;D
http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore/UpdateAsync ROBLOX's example :
local DataStore = game:GetService("DataStoreService"):GetDataStore("Example") game.Players.PlayerAdded:connect(function(player) local key = "user_" .. player.userId --we want to give 50 points to users each time they visit DataStore:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 --oldValue might be nil newValue = newValue + 50 return newValue end) end)
````````
local DS = game:GetService("DataStoreService"):GetDataStore("Points") game.Player.PlayerAdded:connect(plr) local leaderstats = Instance.new("Model",plr) leaderstats.Name = "leaderstats" local lvl = Instance.new("IntValue", leaderstats) lvl.Name = "LVL" lvl.Value = 1 local currency = Instance.new("IntValue", leaderstats) currency.Name = "Gold" currency.Value = 100 while wait(5) do DS:SetAsync(plr.userId.."_DS", currency.Value) end end)