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)

3 comments

0

Did you check if the script found getFolder? Btw, I recommend adding error handlers in case if something goes wrong with the datastore.

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?

0

@TheeDeathCaster yeah I made check for folder but folder is found problem only with SetAsync