Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Tools datastore not saving upon PlayerRemoving?

Asked by 4 years ago
Edited 4 years ago

Hello, so I've been trying to save upon playerremoving but it never wants to work. I even used BindToClose() and I know it works 30 seconds before shutdown they said. But when I leave, the tool wont save.

This is currently my code right now:

01local dataStoreService = game:GetService("DataStoreService")
02local dataStore = dataStoreService:GetDataStore("BackpackSave")
03game.Players.PlayerAdded:Connect(function(player)
04    pcall(function()
05        local tool = dataStore:GetAsync("User-"..player.UserId)
06        if tool then
07            for i,v in pairs(tool) do
08                local toolFound = game.ReplicatedStorage.Items:FindFirstChild(v)
09                if toolFound  then
10                    toolFound:Clone().Parent = player.Backpack
11                end
12            end
13        end
14    end)
15end)
View all 42 lines...

Any help is appreciated...

0
https://developer.roblox.com/en-us/articles/Datastore-Errors Wait 6 seconds between each request User#30567 0 — 4y

2 answers

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

your character is probably spawning after you parent the tool to the backpack, meaning that your backpack gets reset

try parenting a clone of the tool to both player.Backpack and player.StarterGear instead of just player.Backpack

Ad
Log in to vote
0
Answered by 4 years ago

It worked fine for me. Are you sure you have API Services enabled? (Game Settings -> Security -> Enable Studio Access to API Services)? Make sure to restart your studio after you save.

0
Apparently, I get "22:58:38.509 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = User-28814494" WARN, which I'm aware it happens. But I feel like there's something sketchy in my code. TinfoilbotGamer 35 — 4y
0
So its not working, and yes I enabled API services. TinfoilbotGamer 35 — 4y
0
did you press save and restart studio? NotMiskie 78 — 4y
0
Apparently, it just rarely works. Any ways to fix this? TinfoilbotGamer 35 — 4y
0
I would recommend making it also auto-save every few seconds since data stores fail saving on player removed especially when there's only one player in the server NotMiskie 78 — 4y

Answer this question