Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need help in making a currency that saves?

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?

3 comments

0

Go to roblox wiki.

0

Reminder: THIS IS NOT A REQUEST SITE.

0

IM NOT REQUESTING BUT LOOKING FOR A SIMPLE DATASTORE EXPLANATION PFFT -.-

1 answer

✓ Accepted answer

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.

3 comments

0

ik how to use dev products :p

0

Not exactly what I need, but I will try to make that what I want to be.

0

This is no datastore...

This discussion is preserved as it was. New answers, comments, and votes are closed.