when I load my player when trying to retrieve the data, I do not get an error or a success.
on the other hand, the saving does work but randomly.
local DataService = game:GetService("DataStoreService")
local DataStore = DataService:GetDataStore("Doesnotd Matterrigh now")
game.Players.PlayerAdded:Connect(function(player)
local RetrieveData
local success, errorMessage = pcall(function()
end)
if success then
if RetrieveData then
player:WaitForChild("leaderstats").Days.Value = DataStore:GetAsync(player.UserId,player.leaderstats.Days.Value)
print("Retrived")
else
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
print(player," Has Left")
local days = player.leaderstats.Days.Value
local success, errorMessage = pcall(function()
DataStore:SetAsync(player.UserId,days)
end)
if success then
print("All Saved")
else
print(errorMessage)
end
end)
Confused. You just dumped a whole script into a thread and asked people to tell you what you’re doing wrong. What’s wrong in the first place then? You appear to have an issue with the code you’re using but you haven’t specified any kind of details.
It’s important that you read and follow our category guidelines. They exist so that when creating support threads, you have a guideline of information that should be in your post to better help others help you. This isn’t a do-my-work category. Make sure to reference existing resources and documentation for help as well.
If something doesn’t work, debug first and if you truly can’t figure it out, identify where exactly the problem is and what you’ve attempted to fix it so we aren’t repeating things that you’ve already tried.
You’re doing nothing inside the pcalled function, were you meaning to define RetrieveData inside here as your GetAsync? RetrieveData stays nil so it can never be loaded.
game.Players.PlayerAdded:Connect(function(player)
local success, retrievedData = pcall(function()
return DataStore:GetAsync(tostring(player.UserId))
end)
if RetrieveData then
player:WaitForChild("leaderstats"):WaitForChild("Days").Value = retrievedData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local days = player.leaderstats.Days.Value
local success, errorMessage = pcall(function()
DataStore:SetAsync(tostring(player.UserId), days)
end)
if success then
print("Player Saved")
else
print(errorMessage)
end
end)