I recently changed up my DataStore System and was wondering why is wasn't working (I have tried this out of studio)any ideas? any help would be appreciated
local DataStoreService = game:GetService("DataStoreService") local DATA = DataStoreService:GetDataStore("DATA") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("NumberValue") cash.Name = "Cash" cash.Parent = leaderstats local data local success, errormessage = pcall (function() data = DATA:GetAsync(player.UserId.."-cash") end) if success then cash.Value = data else print("An error occurred while loading player data") warn(error) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall (function() DATA:SetAsync(player.UserID.."-cash",player.leaderstats.Cash.Value) end) if success then print("Player Data successfully saved!") else print("An error occurred while saving player data") warn(errormessage) end end)
The Script is named Script
Edit:I am getting a console error of couldn't identity player.UserId
Well first, as previously mentioned you forgot = on line 28 Another possible reason is that you dont save on BindToClose() You should look into that or the game will never save the data of the last player who leaves the server.
https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose