Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I automatically save/load the characters position?

Asked by 8 years ago
Edited 8 years ago

I have tried every way possible manually saving it and automatically saving it doesn't work even with a key. But now I wanna automatically save the characters position upon leave any help?

game.Players.PlayerAdded:connect(function(player)
local Data=game:GetService("DataStoreService"):GetDataStore("Load")
local SaveGui=player:FindFirstChild("ScreenGui"):FindFirstChild("Load")
SaveGui.MouseButton1Down:connect(function()
function clicked()
    if player.DataReady==true then
    Data:GetAsync(player.userId,player.Character:WaitForChild("Torso").Position.Vector3.x,player.Character:WaitForChild("Torso").Position.Vector3.y,player.Character:WaitForChild("Torso").Position.Vector3.z)
        end
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago
local Data=game:GetService("DataStoreService"):GetDataStore("Load")

game.Players.PlayerAdded:connect(function(plr)
    local pos = Data:GetAsync(plr.userId)
    if pos then
        plr.Character:MoveTo(Vector3.new(pos.x, pos.y, pos.z)
    end
end)

game.Player.PlayerRemoving:connect(function(plr)
    local v3 = plr.Character.Torso.Position
    Data:SetAsync(plr.userId, {x = v3.x, y = v3.y, z = v3.z})
end)

It's just the general idea, some parts might give errors.

0
Question for the first one isnt the getasync suppose to load? Upon Join? Instead of using MoveTo why not get the Torsos previous saved position? NotNowSkid 10 — 8y
0
Nvm all of this, your script does not work. NotNowSkid 10 — 8y
0
It might have not worked because of several aspects: - Server might get closed before it saved your position (use OnClose for that), - The Character might already be gone when it tries to get the Torso's position, to fix that you could make some kind of autosave system instead Happywalker 185 — 8y
Ad

Answer this question