In my game, I've implemented a DataStore feature that saves and loads points. Everything seems to be working fine until I attempt to SetAsync in a PlayerRemoved event. ONLY when I'm in studio does this happen. I've even tried saving data automatically after 5 seconds after joining, and that works. The code seems to stop at SetAsync and not run any further after I stop running the game in Studio. This works in the published game though, and I have Studio API on. if it helps, I followed along with TheDevKing's tutorial on Data Persistence. Here's the code:
local data_service = game:GetService("DataStoreService")
local data_store = data_service:GetDataStore("MyData")
-- There is a setasync function before this that works fine
game.Players.PlayerRemoving:Connect(function(plr)
local user_id = plr.UserId
local data = plr.leaderstats.Points.Value
local success, error_msg = pcall(function()
data_store:SetAsync(user_id, data)
end)
if success then
print("Data saved successfully!")
else
print("Data error!")
warn(error_msg)
end
end)
Is there any way to fix this, such as making it faster?

1 comment
Please code block all of your code.