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

Saving and Loading a Player's Position?

Asked by 5 years ago
Edited 5 years ago

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.

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. xPolarium 1388 — 5y
0
Sorry I'm a little confused on your response. Do you mean in studio or here on the forum? Notrealac0unt 19 — 5y
0
Here in the question. Edit this post. Button is right below this comment section. xPolarium 1388 — 5y
View all comments (3 more)
0
According to what I see here, you haven't actually saved or loaded anything SteamG00B 1633 — 5y
0
You make a datastore and a save variable, but they are never used. Are you sure this is your whole script? SteamG00B 1633 — 5y
0
Yes this is all I've done, am I missing something? Notrealac0unt 19 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

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) Notrealac0unt 19 — 5y
0
I meant to do HumanoidRootPart. Sorry. Or you could just use UpperTorso or LowerTorso SirDecent 7 — 5y
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 Notrealac0unt 19 — 5y
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 Notrealac0unt 19 — 5y
View all comments (5 more)
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 SirDecent 7 — 5y
0
Or it may have something to do with DataStoreService not saving or something SirDecent 7 — 5y
0
I tried and it didn't work, only works so far with Local Scripts Notrealac0unt 19 — 5y
0
How about make the position save whenever it's changed or the player leaves (in the server script) SirDecent 7 — 5y
0
Still doesn't work Notrealac0unt 19 — 5y
Ad

Answer this question