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

Saving and Loading a Player's Position?

So for three days now (Not on the whole game just the save & load) I've been working hard on a Roblox turn based RPG. It came to my attention players would need to save and load there game data. So I've read around on DataStores and how to convert CFrame values to a DataStore. But nothing seems to be working.
The Closest I've come to doing this sort of thing is this

  1. Have A ScreenGui in StarterGui
  2. In it I have a Save & Load Button.
  3. In the Save Button there is a Local script

The Local script is the following -

local saveButton = script.Parent
local loadButton = script.Parent.Parent.LoadButton

saveButton.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.SaveLocation.PlayerPosition.Value = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
end)

loadButton.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.SaveLocation.PlayerPosition.Value
end)

Here is my DataStore Script -

local DataStore = game:GetService("DataStoreService")
local save = DataStore:GetDataStore("SavePos")

game.Players.PlayerAdded:Connect(function(plr)
	local spot = Instance.new("Folder",plr)
	spot.Name = "SaveLocation"
	
	local pos = Instance.new("CFrameValue",spot)
	pos.Name = "PlayerPosition"
	
	plr:WaitForChild("X").Value = plr.Character:WaitForChild("HumanoidRootPart").CFrame.x
	plr:WaitForChild("Y").Value = plr.Character:WaitForChild("HumanoidRootPart").CFrame.y
	plr:WaitForChild("Z").Value = plr.Character:WaitForChild("HumanoidRootPart").CFrame.z
	
end)

EDIT - The Local Script does save the CFrame then Load it when the button is clicked, it's the matter of having the SAME CFrame when you leave the game and then rejoin the game

This is my first post on ScriptingHelpers so if I said anything or did anything incorrectly above any feedback or help is appreciated. Thanks.

7 comments

1

Place your code in between the code block. The code block are the two squiggly lines you insert when clicking the blue Lua icon.

0

Sorry I'm a little confused on your response. Do you mean in studio or here on the forum?

0

Here in the question. Edit this post. Button is right below this comment section.

0

According to what I see here, you haven't actually saved or loaded anything

0

You make a datastore and a save variable, but they are never used. Are you sure this is your whole script?

0

Yes this is all I've done, am I missing something?

1 answer

Make one value in the player that's a CFrame value and when you want to change it do "plr.Character.Humanoid.CFrame" instead of having three different values to change. It's quick and makes a little more sense

9 comments

0

Do you mean, HumanoidRootPart, as this is R15 I'm using and Humanoid doesn't use .CFrame if I'm right, (tried before as well)

0

I meant to do HumanoidRootPart. Sorry. Or you could just use UpperTorso or LowerTorso

0

Ok so I did that and it still does the same thing, This is what happens, The SaveLocation folder WITH the CFrame value is put into the local player

0

Messed up, anyways, when I click the save button the CFrame is saved, I move over the baseplate a little then click the load button, then I'm put back to the save location, but when I leave the game then come back, it doesn't work

0

I think it may be because it's inside a localscript. I know gui stuff isn't supposed to be used with normal scripts but I know it works. To test something out make the localscript into a normal script and see if it works

0

Or it may have something to do with DataStoreService not saving or something

0

I tried and it didn't work, only works so far with Local Scripts

0

How about make the position save whenever it's changed or the player leaves (in the server script)

0

Still doesn't work

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