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

How can i make this currencys save?

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)

2 comments

0

Hi, I have a script for that let me go get it.

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

2 answers

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)

1 comment

0

you're supposed to give an explanation when posting an answer but ok >.>

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.

4 comments

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?

0

sorry!

0

Ok I fixed the answer, it was a problem with the first script.

0

Try it now

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