Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help in making a currency that saves?

Asked by 8 years ago

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?

0
Go to roblox wiki. Mokiros 135 — 8y
0
Reminder: THIS IS NOT A REQUEST SITE. Moderance 30 — 8y
0
IM NOT REQUESTING BUT LOOKING FOR A SIMPLE DATASTORE EXPLANATION PFFT -.- PlantChampion 136 — 8y

1 answer

Log in to vote
-1
Answered by 8 years ago

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.

0
ik how to use dev products :p PlantChampion 136 — 8y
0
Not exactly what I need, but I will try to make that what I want to be. PlantChampion 136 — 8y
0
This is no datastore... PlantChampion 136 — 8y
Ad

Answer this question