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

Can you help. Why data is not saving when you use PlayerRemoving?

Asked by
Diltz_3 75
5 years ago

When I'm using event PlayerRemoving Data is not saving.

local DataStore_Service = game:GetService("DataStoreService")
local DS = DataStore_Service:GetDataStore("Hidden")

game.Players.PlayerAdded:Connect(function(Player)
    local newFolder = Instance.new("Folder",game.ServerStorage)
    newFolder.Name = Player.Name
    local Money = Instance.new("IntValue",newFolder)
    Money.Name = "Money"
    Money.Value = DS:GetAsync("Key_"..Player.UserId)
    print("Data Loaded")
end)

game.Players.PlayerRemoving:Connect(function(Player)
    local getFolder = game.ServerStorage:FindFirstChild(Player.Name)
        DS:SetAsync("Key_"..Player.UserId,getFolder.Money.Value)
    print("Data Saved")
end)
0
Did you check if the script found getFolder? Btw, I recommend adding error handlers in case if something goes wrong with the datastore. TheeDeathCaster 2368 — 5y
0
sorry diltz not relating to the question i cant see anything wrong with it myself but TheeDeathCaster can you help me on my DS problem? Donut792 216 — 5y
0
@TheeDeathCaster yeah I made check for folder but folder is found problem only with SetAsync Diltz_3 75 — 5y

Answer this question