hard to really diagnose without seeing a better snippet of the code since this is pretty basic datastore stuff shown
No, nothing yielding, it’s all just events or variable declarations.
I printed a statement directly before the code snippet I sent you, so it’s not a problem.
weird, not sure i really know what to look into from here, sorry man bit hard to tell with just that snippet since its pretty standard stuff you do for datastores, maybe try running the datastore in a modulescript and requiring it where its needed?
This is flustrating, I’m not getting any errors. Sure there isn’t anything else? I’ve been having this problem for a day now.
as i mentioned above, you could probably make a modulescript with commands for editing/setting the datastore, or you could try use a module like DataStore2 which i use on most of my projects
its a great plugin that avoids data loss and other issues with datastores which could help out with whatever is messing with you here haha
Could you try putting that code in a whole new script and telling me what happens?
I already stated, that I tried printing before the code snippet, and there was no problem, it printed fine, so it can’t be a problem.
Other code in the same script is also working fine.
Please just try it. It’s the only thing I can do because as you said earlier:
local P = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local xpStore = DSS:GetDataStore("XP")
P.PlayerRemoving:Connect(function(player)
local suc, err = pcall(function()
xpStore:SetAsync(player.UserId, player.leaderstats.XP.Value)
end)
if not suc then
warn("DATA WAS NOT SAVED! ", player.UserId)
else
print("successfully?")
end
end)
Here’s the code I’m using.
Nothing prints when I leave.
Put this code in a whole new script in ServerScriptService and tell me what it prints:
local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local xpStore = DSS:GetDataStore("XP")
Players.PlayerRemoving:Connect(function(player)
print(player.Name)
local success, errorMessage = pcall(function()
xpStore:SetAsync(player.UserId, player.leaderstats.XP.Value)
end)
if not success then
warn("DATA WAS NOT SAVED!", player.UserId)
warn(errorMessage)
else
print("successfully?")
end
end)
Could you right-click your output window and screenshot the whole thing? I just want to make sure you don’t have settings enabled that prevent you from seeing some prints.
I don’t really know what you mean, but I checked all the contexts and messages, and that’s the only message when I leave.
The weird thing is that your code works perfectly fine for me. Is there no other scripts that affect this one?
I can say that it’s in a folder in ServerScriptService. Not much other than that.
I believe your issue is related to the fact that DataStoreService does not have enough time to save before the Play test actually concludes.
This is very easy to test aswell. Having studio on 60 fps or higher would cause the code to fully save everything before studio stops the play test, however if you were to cap the framerate to lets say 30 or lower THEN studio would simply stop the play test before DataStoreService has any chance to save anything. This can happen even at standard framerates and higher due to a decently long list of other factors but overall any of these factors can cause studio to stop any play test before any DataStoreService gets to finish its job.
Always remember, Data stores need quite a bit of time before they can actually finish saving something.
The problem though is that for some reason, the print inside the .PlayerRemoving fires, but the prints after don’t. The script he sent even worked when I tested it in my published place.
I suggest you try too.
I tested it too.
This happens because the amount of time pcall with the data store function need to complete is worlds less than whatever that print needs. Remember, sending data to remote servers requires different sorts of expectations in speed.
Still, i believe you should try to save data while in the middle of the play test and see if it works.