hi im trying to save my data but i keep getting that error in the output (btw i own the game and i have API Servives On)
my data store script:
local datastore = game:GetService("DataStoreService") local data1 = datastore:GetDataStore("MyDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = plr
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 5000
Cash.Parent = folder
-- Save cash Cash.Value = data1:GetAsync(plr.UserId) data1:SetAsync(plr.UserId, Cash.Value)
game.Players.PlayerRemoving:connect(function() data1:SetAsync(plr.UserId, Cash.Value) end) end)

1 comment
Cash is not defined in your PlayerRemoving event