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

How to create different save files in a single game?

Asked by
fr2013 88
5 years ago

Is there any way to have player data save in files? Like you can select an empty file to begin saving your new stats by starting a new game or you can press on 'Load' and click on your previous game file to continue where you left off?

0
you'll need data store, but yes User#19524 175 — 5y
0
Yeah but I feel like a beginner in Data Store cause I know how to store Cash and Levels and stuff thats all fr2013 88 — 5y

1 answer

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

You'll just have to name the DataStore a different name, like this:

local SaveFileOne = game:GetService('DataStoreService'):GetDataStore("savefile1")
local SaveFileTwo = game:GetService('DataStoreService'):GetDataStore("savefile2")

And do the tasks like you did the first one

SaveFileTwo:GetAsync(playerkey)
SaveFileTwo:SetAsync(playerkey,datatable)

EDIT:

If you want someone to have 2 save files:

Clicking the "Load Save File 1" Gui that you've made LOCAL SCRIPT:

local button = --where your button is
button.MouseButton1Click:Connect(function()
local EventOne = game:GetService("ReplicatedStorage").EventOne -make a "Remote Event" and put it in ReplicatedStorage. You can name it anything, i named it EventOne.
EventOne:FireServer() --the local script tells the server that the button was clicked
end)

SERVER SCRIPT: Do your GetAsync here for the first save file.

local SaveFileOne = game:GetService('DataStoreService'):GetDataStore("SaveFile1")
local EventOne = game:GetService("ReplicatedStorage").EventOne

EventOne.OnServerEvent:Connect(function(player) --fires when EventOne was fired to the server.
    local playerkey = "player-"..player.userId
    local SaveFiles = SaveFileOne:GetAsync(playerkey)
        --the save files you want them to recover
end)

Clicking "Load Save File 2" gui that you made

LOCAL SCRIPT:

local button = --where your button is
button.MouseButton1Click:Connect(function()
local EventTwo = game:GetService("ReplicatedStorage").EventTwo -make another remote event
EventTwo:FireServer()
end)

SERVER SCRIPT:

Do your GetAsync here for the second save file.

local SaveFileTwo = game:GetService('DataStoreService'):GetDataStore("SaveFile2")
local EventTwo = game:GetService("ReplicatedStorage").EventTwo

EventTwo.OnServerEvent:Connect(function(player)
    local playerkey = "player-"..player.userId
    local SaveFiles = SaveFileTwo:GetAsync(playerkey)
        --the save files you want them to recover
end)
0
So how do I implement them into a Gui? fr2013 88 — 5y
0
You'd have to fire RemoteEvents since the DataStore can only be accessed through Scripts and not LocalScripts. So fire a remote event when the gui is clicked in a local script, and then have the datastore in a server script. ShinyGriffin 129 — 5y
0
And finally do I use the GetASync and SetASync when they click on the gui in the local script? fr2013 88 — 5y
0
No, you should put the GetASync and SetAsync in the Server Script. The only thing the Gui should do is fire the event, and the server script should handle the data store. ShinyGriffin 129 — 5y
View all comments (7 more)
0
But yet, do a GetSync event when the button is pressed, and it's usually only nessasary to save when the player leaves so the queue doesnt fill. ShinyGriffin 129 — 5y
0
Well I'm kinda lost of what I'm doing now fr2013 88 — 5y
0
I'll post an answer to try to help out, gimma a sec ShinyGriffin 129 — 5y
0
Ok i edited my original answer ShinyGriffin 129 — 5y
0
And will this like keep levels, exp, cash, and backpack inventory separated/cleared when I join a new game file and save the whole thing in that one game file unless starting on another game file? fr2013 88 — 5y
0
Since I also have a character save/load on character position script that whenever they join in a game it’ll save where ever their at and it seems to work fine since it goes back to the spawn but I don’t think it saves it a lot in the file fr2013 88 — 5y
0
I think that all depends on how you;re creating your save script. If your backpack, position, cash etc is located on SaveFile1, loading a GetAsync() from SaveFile2 will start you fresh in all your values. Changing SaveFile2 does not affect SaveFile1 ShinyGriffin 129 — 5y
Ad

Answer this question