Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I automatically save/load the characters position?

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

✓ Accepted answer
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.

3 comments

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?

0

Nvm all of this, your script does not work.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.