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

How do i save a value in Datastore?

Asked by 3 years ago

I've done Leaderstats but I don't know how to save values.

2 answers

Log in to vote
0
Answered by
NeptyU 15
3 years ago
Edited 3 years ago
local DS = game:GetService("DataStoreService"):GetDataStore("Data")

local StatName = "Cash"

game.Players.PlayerAdded:Connect(function(user)
    user.leaderstats:FindFirstChild(StatName).Value = DS:GetAsync(user.UserId)
end)
game.Players.PlayerRemoving:Connect(function(user)
    DS:SetAsync(user.UserId,user.leaderstats:FindFirstChild(StatName).Value)
end)

Save and load script. Basic save and load, It can be made better using UpdateAsync() but this will also work.

0
You should use :IncrementAsync(). Ziffixture 6913 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Take a look at this question's top answer, while the question isn't completely related, the answer should probably help you out

https://scriptinghelpers.org/questions/41698/how-to-save-multiple-values-in-a-datastore

Answer this question