It saves the player's position when they leave then teleports them there when they rejoin, I honestly do not know what went wrong. It is probably with the datastore.
game.Players.PlayerAdded:connect(function(p) pos = Instance.new("CFrameValue",p) pos.Name = "position" p.CharacterAdded:connect(function(c) if game:GetService("DataStoreService"):GetDataStore("data1"):GetAsync(p.Name.."_pos") then c.Torso.CFrame = game:GetService("DataStoreService"):GetDataStore("data1"):GetAsync(p.Name.."_pos") end end) end) game.Players.PlayerRemoving:connect(function(p) game:GetService("DataStoreService"):GetDataStore("data1"):SetAsync(p.Name.."_pos",p.position.Value) end) while true do for i,v in pairs(game.Players:GetChildren()) do if v.Character:FindFirstChild("Torso") then v.position.Value = v.Character.Torso.CFrame end end wait() end
Some notes:
c.Torso.CFrame = pos.Value
(but be sure to set pos.Value to a spot where they can spawn safely).v.Character
is ever nil (ex character not loaded)CFrame.new(position, positionToLookAt)
. Assuming I'm right about the CFrames not being stored in a datastore, I recommend storing these two Vector3's either in a table or as a string. Ex, you might store it like this "10,5.1,-3.2,11,5.1,-3.2", where the first 3 numbers are the XYZ of position
and the last 3 numbers are the XYZ of the positionToLookAt