#How to store player data
1 messages · Page 1 of 1 (latest)
using profilestore
search up rileybytes on youtube and youll find it
Ty i will see later , And can u tell why are http service used?
i don't think httpservice is used
oh you dont have to i think
Ask @mint drum to memorize them for u
you can use DataStoreService to store it, first you have to get a DataStore passing a string to it, and to load you use GetAsync, and to set you use SetAsync
I recommend always using pcall for it, to error treatment in case of failure
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local GameData = DataStoreService:GetDatatStore("GameData")
local DataContainer = {}
local function GetDefaultData()
return {
Money = 0,
Level = 1,
Exp = 0
}
end
local function OnPlayerAdded(Player)
local Success, Result = pcall(function()
return GameData:GetAsync(Player.UserId)
end)
if not Success then
warn(`Error trying to load {Player.Name}'s data: {Result}`)
end
DataContainer[Player] = Result or GetDefaultData()
end
local function OnPlayerRemoving(Player)
if not DataContianer[Player] then
warn(`No data to save for {Player.Name}`)
return
end
local Success, Result = pcall(function()
GameData:SetAsync(Player.UserId, DataContainer[Player])
end)
if not Success then
warn(`Error trying to save {Player.Name}'s data: {Result}`)
end
end
for _, Player in Players:GetPlayers() do OnPlayerAdded(Player) end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
just made it now, but you can use as a reference: GetAsync to get player's data using an ID (usually player's user id), and to set (save) the same thing: using an ID, and passing the data you want to save
for the error treatment, I recomend using some retries (3 or more), and a delay for it
Check out my response to a similar question https://discord.com/channels/448986884497211392/1449878865617883236
profile store >>> data store service
U sound stupid
ProfileStore is literally made with data store service
yes i know but you suggested dss over profile store
Where