Hi, I am just a beginner in Lua. Can someone help and explain to me DataStore and how it works? I want to make a in-game currency you can buy for robux and need it to save next time you play. The problem is : I don't know how DataStore works! Can someone help me?
There's already a useful leaderstats saver, put this into a regular script, and place it in Workspace:
function onPlayerEntered(player) wait()-- Change to wait for player longer. player:WaitForDataReady() repeat wait() until player:FindFirstChild("leaderstats") if player.DataReady then if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do local ScoreLoaded = player:LoadNumber(score[i].Name) wait() if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do player:SaveNumber(score[i].Name,score[i].Value) end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving)
To purchase currency with robux, you'll need to use Developer Products, if you want to allow players to buy the currency multiple times.