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

How do i save a value in Datastore?

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

2 answers

✓ Accepted answer
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.

1 comment

0

You should use :IncrementAsync().

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