Below is my datastore script for when the system saves two variables, 'Points' and 'Wins'. I have previously defined 'dss' as the DataStoreService, 'mds' and 'wds' as DataStores previously created (I know these variables are fine)
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errormessage = pcall(function() --LOADING POINTS
data = mds:GetAsync(tostring(player.UserId.."-points"))
end)
if success then
print("success loading data")
player:WaitForChild("leaderstats").Points.Value=data
local check = tostring(data)
print(check)
else
print("Error getting data")
warn(errormessage)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local winsdata
local success, errormessage = pcall(function() --LOADING WINS
winsdata = wds:GetAsync(tostring(player.UserId.."-wins"))
end)
if success then
print("success loading data")
player:WaitForChild("leaderstats").Wins.Value=winsdata
local winscheck = tostring(winsdata)
print(winscheck)
else
print("Error getting data")
warn(errormessage)
end
end)
These work absolutely fine and load in the variables previously saved just fine. However today when I logged onto studio, my save script suddenly wasn't working.
game.Players.PlayerRemoving:Connect(function(player)
print("this script has run")
local success, errormessage = pcall(function()
print("this pcall also ran")
mds:SetAsync(player.UserId.."-points",player.leaderstats.Points.Value)
end)
if success then
print("Data saved succesfully.")
else
print("Error saving data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local asuccess, aerrormessage = pcall(function()
print("this script has run")
wds:SetAsync(player.UserId.."-wins",player.leaderstats.Wins.Value)
end)
if asuccess then
print("Data saved succesfully.")
else
print("Error saving data")
warn(aerrormessage)
end
end)
In the output, "this script has run" appears twice as it should and so does "this pcall also ran", but there are no "Data saved successfully" or any errormessages at all. Is there a problem with the pcall function returning success? Surely even if it returned nil then the else part would still run? Please help , thanks!

1 comment
edit:- fixed codeblock