Answers for "roblox scripts to save player data"

3

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 :)
Posted by: Guest on January-04-2021

Browse Popular Code Answers by Language