CODE:
local DataStoreService = game:GetService("DataStoreService")
local locationStore = DataStoreService:GetDataStore("LocationStore")
game.Players.PlayerAdded:Connect(function(player)
local character = game.Workspace:WaitForChild(player.Name)
local data
local success, err = pcall(function()
data = locationStore:GetAsync(player.UserId.."-position")
end)
if success then
if data and data ~= {x = 0, y = 3, z = 0} then
character.HumanoidRootPart.Position = Vector3.new(data.x, data.y, data.z)
else
print("No data found!")
locationStore:SetAsync(player.UserId.."-position", {
x = 0,
y = 3,
z = 0
})
end
else
warn("There was an error while getting data!")
warn("Error code:", err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local character = game.Workspace:WaitForChild(player.Name)
local success, err = pcall(function()
locationStore:SetAsync(player.UserId.."-position", {
x = character.HumanoidRootPart.Position.X,
y = character.HumanoidRootPart.Position.Y,
z = character.HumanoidRootPart.Position.Z
})
end)
if success then
print("Data successfully saved!")
else
warn("There was an error while saving data!")
warn(err)
end
end)

1 comment
What errors or problems are you getting?