Save Location

Data Store Setup

1. Make sure your game is published to Roblox

2. Click Game Settings, then Options, then Enable API Services

3. Test game on Roblox Website

4. startLocation can be any position

ServerScriptService

local DataStoreService = game:GetService('DataStoreService')

local playerData = DataStoreService:GetDataStore('PlayerData')

local RunService = game:GetService('RunService')


local startLocation = Vector3.new(-14, 0.6, -32)


local function onPlayerJoin(player)

local leaderstats = Instance.new('Folder')

leaderstats.Name = 'leaderstats'

leaderstats.Parent = player

local location = Instance.new('Vector3Value')

location.Name = 'Location'

location.Parent = player

local playerLocationId = 'Location_'..player.UserId

local LocationData = playerData:GetAsync(playerLocationId)

if LocationData then

location.Value = Vector3.new(LocationData[1],LocationData[2],LocationData[3])

player.CharacterAdded:Connect(function(chr)

local hrp = chr:WaitForChild('HumanoidRootPart')

RunService.Stepped:wait()

hrp.CFrame = CFrame.new(location.Value)

end)

else

location.Value = startLocation

end

end


local function convert(vec)

return {vec.X, vec.Y, vec.Z}

end


local function onPlayerExit(player)

local success, err = pcall(function()

local playerLocationId = 'Location_'..player.UserId

playerData:SetAsync(playerLocationId, convert(player.Location.Value))

end)

if not success then

warn('Could not save data')

end

end


game.Players.PlayerAdded:Connect(onPlayerJoin)

game.Players.PlayerRemoving:Connect(onPlayerExit)

Script for Checkpoint Part

local part = script.Parent


local function updateLocation(otherPart)

local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)

if player then

player.Location.Value = otherPart.Parent.HumanoidRootPart.Postion

end

end


part.Touched:Connect(updateLocation)