best data saver roblox code example

Example: how to save data roblox stuiod

local DataStoreService = game:GetService("DataStoreService")
local goldStore = DataStoreService:GetDataStore("PlayerGold")
 
-- Data store key and value
local playerUserID = 505306092 --could be Player.UserID
local playerGold = 250 --set somewhere else
 
-- Set data store key
local setSuccess, errorMessage = pcall(function()
	goldStore:SetAsync(playerUserID, playerGold)
end)
if not setSuccess then
	warn(errorMessage)
end
 
-- Read data store key
local getSuccess, currentGold = pcall(function()
	return goldStore:GetAsync(playerUserID)
end)
if getSuccess then
	print(currentGold)
end
--Credit: https://developer.roblox.com/en-us/articles/saving-data-introduction
--Hope this helps :)

Tags:

Misc Example