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

How can i make this currencys save?

Asked by 3 years ago
01game.Players.PlayerAdded:Connect(function(plr)
02    local a = Instance.new("Folder",plr)
03    a.Name = "leaderstats"
04    local m = Instance.new("IntValue",a)
05    m.Value = 0
06    m.Name = "Cash"
07    local x = Instance.new("IntValue",a)
08    x.Value = 0
09    x.Name = "Mushrooms"
10end)
0
Hi, I have a script for that let me go get it. minerpro_2 0 — 3y
0
local DS = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait(5) local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Name local save2 = plr.leaderstats.Name local GetSaved = DS:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] else local NumberForSaving = {save1.Value, save minerpro_2 0 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

local DS = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait(5) local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Name local save2 = plr.leaderstats.Name

1local GetSaved = DS:GetAsync(plrkey)
2if GetSaved then
3    save1.Value = GetSaved[1]
4    save2.Value = GetSaved[2]
5 
6else
7    local NumberForSaving = {save1.Value, save2.Value}
8    DS:GetAsync(plrkey, NumberForSaving)
9end

end)

game.Players.PlayerRemoving:Connect(function(plr) DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Name.Value, plr.leaderstats.Name.Value}) end)

0
you're supposed to give an explanation when posting an answer but ok >.> NGC4637 602 — 3y
Ad
Log in to vote
0
Answered by
epoke466 100
3 years ago
Edited 3 years ago

Use this as the script for the leaderstats otherwise known as the script that was in your question:

01local datastore = game:GetService("DataStoreService")
02local ds1 = datastore:GetDataStore("CashSave")
03local ds2 = datastore:GetDataStore("MushroomsSave")
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    local a = Instance.new("Folder",plr)
07    a.Name = "leaderstats"
08    local m = Instance.new("IntValue",a)
09    m.Value = ds1:GetAsync(plr.UserId) or 0
10    ds1:SetAsync(plr.UserId, m.Value)
11    m.Name = "Cash"
12    local x = Instance.new("IntValue",a)
13    x.Value = ds2:GetAsync(plr.UserId) or 0
14    ds2:SetAsync(plr.UserId, x.Value)
15    x.Name = "Mushrooms"
16end)

Then put another script in StarterPlayer > StarterPlayerScripts:

1local datastore = game:GetService("DataStoreService")
2local ds1 = datastore:GetDataStore("CashSave")
3local ds2 = datastore:GetDataStore("MushroomsSave")
4local player = script.Parent.Parent
5 
6while wait() do
7ds1:SetAsync(player.UserId, player.leaderstats.Cash.Value)
8ds2:SetAsync(player.UserId, player.leaderstats.Mushrooms.Value)
9end

After you make these scripts, go into the Game Settings. Here is a picture: https://www.linkpicture.com/view.php?img=LPic60c7adb803e1a33241333

From there go to security and enable studio to access API Services.

0
Just a question why when i try the game there is a leaderstat but it is named Value. What happend or what do i do now? shadow93126 10 — 3y
0
sorry! epoke466 100 — 3y
0
Ok I fixed the answer, it was a problem with the first script. epoke466 100 — 3y
0
Try it now epoke466 100 — 3y

Answer this question