What do you want to achieve? Keep it simple and clear!
I am trying to create mechanism similar to PD (Permanent Death), basically removing player data upon death, but I want to make it so if player leave the game, their player data would be deleted.
What is the issue? Include screenshots / videos if possible!
Naturally, I scripted a basic script to do that, but it just don’t work for some reason, the script is provided below:
game.Players.PlayerRemoving:Connect(function(player)
local dataStore = game:GetService("DataStoreService"):GetDataStore("LumiData")
local key = tostring(player.UserId)
local success, err = pcall(function()
dataStore:RemoveAsync(key)
end)
if success then
print("Player data removed successfully")
else
warn("Failed to remove player data: " .. err)
end
end)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked everywhere on Devforums, tried it but it doesn’t work, I am not sure why, my data is structured in simple way - its stored in “LumiData” and player’s data is referenced using UserID, with stats in it and everything.
A potential issue can be the way you access the key, you are using tostring().
Are you sure the key is a string and not just a number? Since you are using the UserId.
Also, does it print anything? If so, what does it print?
Thanks for small advice, and weirdly, I added print statement and changed PlayerRemoving to PlayerAdded as it would be easier to test, it does execute the pcall, but it doesn’t remove the data, I still have same stats in leaderstats.
edit: logs
Yes, you are right, data is still there even if I rejoined.
Clearing the leaderstats beforing clearing the data seemed to have fixed the problem, and I also got warning “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1989818146” Is this important and something that I should worry about?
This happens when you call too many DataStore requests, you shouldn’t really worry about it. Unless when the log is full of it, then you need to change the way you handle data.