I've been working on this save system for a few hours however for some reason it throws me the error of "19:38:14.934 - ServerScriptService.playerHandler:43: attempt to index local 'part' (a nil value)" Hoping somebody will know why Here is the script:
local players = game:GetService("Players") local datastoreService = game:GetService("DataStoreService") local saveDataStore = datastoreService:GetDataStore("SaveDataTest") local function savePlayerData(player) local success,err = pcall(function() local savedata = {} for _,stat in pairs(player.leaderstats:GetChildren()) do savedata[stat.Name] = stat.Value end saveDataStore:SetAsync(player.UserId,savedata) end) if not success then return err end end players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue") stats.Name = "leaderstats" stats.Parent = player local stage = Instance.new("IntValue") stage.Name = "Stage" stage.Parent = stats local data = saveDataStore:GetAsync(player.UserId) if data then print(data.Stage) for _,stat in pairs(stats:GetChildren()) do stat.Value = data[stat.Name] end else print(player.Name .. " has no data") end player.CharacterAdded:connect(function(char) local hum,hrp = char:WaitForChild("Humanoid"),char:waitForChild("HumanoidRootPart") wait() if hum and hrp then if stage.Value ~= 0 then local part = workspace.obbyStages:FindFirstChild(stage.Name) hrp.CFrame = part.CFrame + Vector3.new(0,1,0) end end end) end) players.PlayerRemoving:connect(function(player) local err = savePlayerData(player) if err then print(err) end end) game:BindToClose(function() for _,plr in pairs(players:GetPlayers()) do local err = savePlayerData(player) if err then print(err) end end wait(2) end)
*Assuming your saving script works
Instead of using (line 38)
local hum,hrp = char:WaitForChild("Humanoid"),char:waitForChild("HumanoidRootPart")
try using
repeat wait() until char.Humanoid repeat wait() until char.HumanoidRootPart local hum,hrp = char:FindFirstChild("Humanoid"),char:FindFirstChild("HumanoidRootPart")