So I made a Data Store that saves both tools and money, but for some reason it doesn't work. The output doesn't show any errors so I got a dead end.
The Code:
local DSS = game:GetService("DataStoreService")
local MoneySave = DSS:GetDataStore("General", "Money")
local GearSave = DSS:GetDataStore("General", "Gear")
game.Players.PlayerAdded:Connect(function(player)
local key = "player-".. player.UserId
pcall(function()
local money = MoneySave:GetAsync(key)
local gear = GearSave:GetAsync(key)
if money then
player:WaitForChild("leaderstats"):WaitForChild("Money").Value = MoneySave[1]
else
local MoneyForSaving = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
MoneySave:GetAsync(key, MoneyForSaving)
end
if gear then
for _,v in pairs(gear) do
local gears = game:GetService("ReplicatedStorage"):FindFirstChild(v)
if gears then
gears:Clone().Parent = player.Backpack
if not player.StarterGear:FindFirstChild(v) then
gears:Clone().Parent = player.StarterGear
end
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "player-".. player.UserId
pcall(function()
local MoneyToSave = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
local GearToSave = {}
for _,v in pairs(player.Backpack) do
table.insert(GearToSave, v.Name)
end
end)
end)
And please, tell me what I did wrong

2 comments
hey, I made a script like this. I found a solution. Here's the answer: https://scriptinghelpers.org/
https://scriptinghelpers.org/questions/59510/datastore-script-not-saving-correctly