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
game.Players.PlayerAdded:Connect(function(plr)
    local a = Instance.new("Folder",plr)
    a.Name = "leaderstats"
    local m = Instance.new("IntValue",a)
    m.Value = 0
    m.Name = "Cash"
    local x = Instance.new("IntValue",a)
    x.Value = 0
    x.Name = "Mushrooms"
end)
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

local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
    save1.Value = GetSaved[1]
    save2.Value = GetSaved[2]

else
    local NumberForSaving = {save1.Value, save2.Value}
    DS:GetAsync(plrkey, NumberForSaving)
end

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:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSave")
local ds2 = datastore:GetDataStore("MushroomsSave")

game.Players.PlayerAdded:Connect(function(plr)
    local a = Instance.new("Folder",plr)
    a.Name = "leaderstats"
    local m = Instance.new("IntValue",a)
    m.Value = ds1:GetAsync(plr.UserId) or 0
    ds1:SetAsync(plr.UserId, m.Value)
    m.Name = "Cash"
    local x = Instance.new("IntValue",a)
    x.Value = ds2:GetAsync(plr.UserId) or 0
    ds2:SetAsync(plr.UserId, x.Value)
    x.Name = "Mushrooms"
end)

Then put another script in StarterPlayer > StarterPlayerScripts:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSave")
local ds2 = datastore:GetDataStore("MushroomsSave")
local player = script.Parent.Parent

while wait() do
ds1:SetAsync(player.UserId, player.leaderstats.Cash.Value)
ds2:SetAsync(player.UserId, player.leaderstats.Mushrooms.Value)
end

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