#data stores behaving weirdly
1 messages · Page 1 of 1 (latest)
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerData")
local PlayerHandler = require(game.ReplicatedStorage.Modules.PlayerHandler)
local ActivePlayers = {}
Players.PlayerAdded:Connect(function(player)
local playerObject = PlayerHandler.CreatePlayer(player)
local playerData
local success, err = pcall(function()
playerData = PlayerDataStore:GetAsync(player.UserId)
end)
if success then
print(playerData)
end
if playerData == nil then
local success, err = pcall(function()
PlayerDataStore:SetAsync(player.UserId, playerObject)
end)
end
ActivePlayers[player.UserId] = playerObject
end)
Players.PlayerRemoving:Connect(function(player)
print(ActivePlayers)
local playerObject = ActivePlayers[player.UserId]
local success, err = pcall(function()
PlayerDataStore:UpdateAsync(player.UserId, function(playerObject)
local playerData = playerObject
return playerData
end)
end)
if success then
print("data saved")
ActivePlayers[player.UserId] = nil
end
if not success then
print(err)
end
end)```
Instead of Playerdat = PlayersDataStore:GetAsync maybe do return PlayersDataStore:GetAsync
Also its not success, err it’s success, data
wat
i thought err was for like
the error message if the pcall fails
pcall returns true,data or false,string
Why not use the new one Module ProfileStore or ProfileService an (Legacy)? It handles everything you need, safe server switching fixing duplication and data overwrite issues, instead of relying on this old one
https://devforum.roblox.com/t/profilestore-save-your-player-data-easy-datastore-module/3190543
“ProfileStore” by loleris (Successor module to ProfileService) [GitHub repo] ProfileStore is a Roblox DataStore wrapper that streamlines auto-saving, session locking and a few other features for the game developer. ProfileStore’s source code runs on a single ModuleScript. Read documentation here: ProfileStore wiki (Click me) Get the m...
im new so its a bit confusing
but i could try
why u saving on player removing lol
just add it to the datastore when a player gets an item its way better
Yeah datastore gets exhausted