local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local char = player.Character or player.CharacterAdded:wait() local ack = Instance.new("IntValue") ack.Name = "leaderstats" local ack2 = Instance.new("IntValue") ack2.Name = "Stage" ack2.Value = 1 ack2.Parent = ack ack.Parent = player local ack3 = Instance.new("IntValue", ack) ack3.Name = "Prestige" ack3.Value = 0 local Folder = Instance.new("Folder", player) local ack4 = Instance.new("IntValue", player) ack4.Name = "Skips" ack4.Value = 0 player:LoadCharacter() local ls = player.leaderstats local sl = game.Workspace:FindFirstChild(ls.Stage.Value) print(sl.Position) char.UpperTorso.CFrame = sl.CFrame + Vector3.new(0,3,0) local char = player.Character or player.CharacterAdded:wait() print(sl.CFrame) local data local data2 local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId .. "-Stage") data2 = myDataStore:GetAsync(player.UserId .. "-Prestige") end) if success then ack2.Value = data local sl = game.Workspace:FindFirstChild(ls.Stage.Value) local char = player.Character or player.CharacterAdded:wait() if char:WaitForChild("UpperTorso") then char:WaitForChild("UpperTorso").CFrame = sl.CFrame + Vector3.new(0,3,0) end print(sl) ack3.Value = data2 else ack2.Value = 1 warn(errormessage) end workspace.ChildAdded:Connect(function(obj) if obj.Name == player.Name then if obj:WaitForChild("UpperTorso") or obj:WaitForChild("Torso") then local sl = game.Workspace:FindFirstChild(ls.Stage.Value) obj:WaitForChild("UpperTorso").CFrame = obj:WaitForChild("UpperTorso").CFrame + Vector3.new(0,3,0) print(sl.CFrame) end wait() if obj:WaitForChild("UpperTorso") or obj:WaitForChild("Torso") then local sl = game.Workspace:FindFirstChild(ls.Stage.Value) obj:WaitForChild("UpperTorso").CFrame = sl.CFrame + Vector3.new(0,3,0) end end end) end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId .. "-Stage", player.leaderstats.Stage.Value) myDataStore:SetAsync(player.UserId .. "-Prestige", player.leaderstats.Prestige.Value) end) if success then print("Data Saved!") else warn(errormessage) end end)
If a player has data they will spawn in the right place after dying once. If a player does not have data they will be on stage 0 and fall to their death infinitely.
On line 40: Attempt to index nil with 'CFrame'
local char = player.Character
That's what line 5 should be.
char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,3,0)
That's what line 40 should be.
local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local char = player.Character or player.CharacterAdded:wait() local ack = Instance.new("IntValue") ack.Name = "leaderstats" local ack2 = Instance.new("IntValue") ack2.Name = "Stage" ack2.Value = 1 ack2.Parent = ack ack.Parent = player local ls = player.leaderstats ls:WaitForChild("Stage").Value = 1 local ack3 = Instance.new("IntValue", ack) ack3.Name = "Prestige" ack3.Value = 0 local Folder = Instance.new("Folder", player) local ack4 = Instance.new("IntValue", player) ack4.Name = "Skips" ack4.Value = 0 local char = player.Character or player.CharacterAdded:wait() local sl = game.Workspace:WaitForChild(ls.Stage.Value) print(ls.Stage.Value) local data local data2 print(ls.Stage.Value) local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId .. "-Stage") data2 = myDataStore:GetAsync(player.UserId .. "-Prestige") print(ls.Stage.Value) end) if success then if data ~= nil then print(data) ack2.Value = data if char:WaitForChild("HumanoidRootPart") then print("1") local sl = game.Workspace:WaitForChild(ls.Stage.Value) char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,3,0) print(sl) end else local sl = game.Workspace:WaitForChild(ls.Stage.Value) end local char = player.Character or player.CharacterAdded:wait() if char:WaitForChild("HumanoidRootPart") then local sl = game.Workspace:WaitForChild(ls.Stage.Value) char:WaitForChild("HumanoidRootPart").CFrame = char:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0,3,0) char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,3,0) print(sl) print(sl.Position) end ack3.Value = data2 else local sl = game.Workspace:FindFirstChild(ls.Stage.Value) local char = player.Character or player.CharacterAdded:wait() if char:WaitForChild("HumanoidRootPart") then char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,3,0) warn(errormessage) end end workspace.ChildAdded:Connect(function(obj) if obj.Name == player.Name then if obj:WaitForChild("HumanoidRootPart") then local sl = game.Workspace:FindFirstChild(ls.Stage.Value) obj:WaitForChild("HumanoidRootPart").CFrame = obj:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0,3,0) print(sl.CFrame) end wait() if obj:WaitForChild("HumanoidRootPart") then local sl = game.Workspace:FindFirstChild(ls.Stage.Value) obj:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,3,0) end end end) end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId .. "-Stage", player.leaderstats.Stage.Value) myDataStore:SetAsync(player.UserId .. "-Prestige", player.leaderstats.Prestige.Value) end) if success then print("Data Saved!") else warn(errormessage) end end)
This is the fixed code.