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
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.
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