For some reason on my upgrade saver's code just gives me an error on line 34 saying "Attempt to index nil with 'Upgrades' And here is the code
local dataService = game:GetService("DataStoreService") local upgradeData = dataService:GetDataStore("upgradeStorage") local Players = game:GetService("Players") game.Players.PlayerAdded:Connect(function(player) local upgradesFolder = Instance.new("Folder", player) upgradesFolder.Name = "Upgrades" local rebirthButtons = Instance.new("IntValue", upgradesFolder) rebirthButtons.Name = "rebirthButtons" rebirthButtons.Value = 0 local UpgradesData = upgradeData:GetAsync(player.UserId) if UpgradesData ~=nil then rebirthButtons.Value = UpgradesData[1] end end) game.Players.PlayerRemoving:Connect(function(player) local upgrades = {} for _, child in pairs(player.Upgrades:GetChildren()) do table.insert(upgrades,child.Value) end pcall(function() upgradeData:SetAsync(player.UserId, upgrades) end) end) game:BindToClose(function(player) for _, Player in pairs(game.Players:GetChildren()) do local upgrades = {} for _, child in pairs(player.Upgrades:GetChildren()) do table.insert(upgrades,child.Value) end pcall(function() upgradeData:SetAsync(player.UserId, upgrades) end) end end)
Try this
local dataService = game:GetService("DataStoreService") local upgradeData = dataService:GetDataStore("upgradeStorage") local Players = game:GetService("Players") game.Players.PlayerAdded:Connect(function(player) local upgradesFolder = Instance.new("Folder", player) upgradesFolder.Name = "Upgrades" local rebirthButtons = Instance.new("IntValue", upgradesFolder) rebirthButtons.Name = "rebirthButtons" rebirthButtons.Value = 0 local UpgradesData = upgradeData:GetAsync(player.UserId) if UpgradesData ~=nil then rebirthButtons.Value = UpgradesData[1] end end) game.Players.PlayerRemoving:Connect(function(player) local upgrades = {} for _, child in pairs(player.Upgrades:GetChildren()) do table.insert(upgrades,child.Value) end pcall(function() upgradeData:SetAsync(player.UserId, upgrades) end) end) game:BindToClose(function() -- no argument here for _, player in pairs(game.Players:GetChildren()) do -- changed "Player" to "player" local upgrades = {} for _, child in pairs(player.Upgrades:GetChildren()) do table.insert(upgrades,child.Value) end pcall(function() upgradeData:SetAsync(player.UserId, upgrades) end) end end)