Ok so, i want to make an script that saves a players position when they disconnect from the game and when they join back, they are in the same position as they were left. Please help!
local locations = {} while wait(1) do for _,player in pairs(game.Players:GetChildren()) do if player and player.Character and player.Character.Parent ~= nil then locations[player] = player.Character.Torso.Position end end end game.Players.PlayerRemoving:connect(function(player) local lastlocation = locations[player] locations[player] = nil -- garbage collection end)
I tried this but, it obviously wouldn't work. :(
local LastPositionDataStore = game:GetService("DataStoreService"):GetDataStore("LastPos") game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local HRP = char:WaitForChild("HumanoidRootPart") HRP.Position = 0,3,0 or LastPositionDataStore:GetAsync(player.UserId) --Gets the last position of the player's HumanoidRootPart position end) end) game.Players.PlayerRemoving:Connect(function(player) local char = player.Character local HRP = char:WaitForChild("HumanoidRootPart") LastPositionDataStore:SetAsync(player.UserId,HRP.Position) --Saves the last position of the player's HumanoidRootPart position end)