i made a obby save script with a table but the server says that it saves when you leave but when you join it does not load your data but there is no errors showing.
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("MyDataStore") game.Players.PlayerAdded:Connect(function(player) local ack = Instance.new("Folder") ack.Name = "leaderstats" ack.Parent = player local ack2 = Instance.new("IntValue") ack2.Name = "Stage" ack2.Parent = ack local data local success, errormassage = pcall(function() data = DataStore:SetAsync(player.UserId.."-stage") end) if success then ack2 = data else print("there was an error whilst getting your data") warn(errormassage) end local test = player.leaderstats.Stage.Value end) function oa(object) wait() local player = game.Players:playerFromCharacter(object) if player ~= nil then local ls = player.leaderstats local sl = game.Workspace:FindFirstChild(ls.Stage.Value) print("gah") object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0) if sl ~= nil then object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0) end end end game.Workspace.ChildAdded:connect(oa) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetAsync(player.UserId.."-stage",player.leaderstats.Stage.Value) end) if success then print("Player Data successfully saved!") else print("there was an error when saving data") warn(errormessage) end end)
Try to see if this works
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("MyDataStore") game.Players.PlayerAdded:Connect(function(player) local ack = Instance.new("Folder") ack.Name = "leaderstats" ack.Parent = player local ack2 = Instance.new("IntValue") ack2.Name = "Stage" ack2.Parent = ack local success, data = pcall(function() return DataStore:GetAsync(player.UserId.."-stage") --//You were calling SetAsync to get data when it should have been GetAsync end) if success then ack2.Value = data else print("there was an error whilst getting your data") warn(data) end player.CharacterAdded:Connect(function(Character) --//this is to get rid of the childadded event on workspace, this gets the character directly local Root = Character:WaitForChild("HumanoidRootPart") --//Better to teleport using the rootpart than the torso local s1 = game.Workspace:FindFirstChild(ack2.Value) --//Trys to get the stage if (s1) then Root.CFrame = s1.CFrame + Vector3.new(0,3,0) else Root.CFrame = Root.CFrame + Vector3.new(0,3,0) end end) end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetAsync(player.UserId.."-stage",player.leaderstats.Stage.Value) end) if success then print("Player Data successfully saved!") else print("there was an error when saving data") warn(errormessage) end end)
I changed some things to make the code look better, and I should have fixed your problem.