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

How to save more than one data in one script?

Asked by 4 years ago

I'm really interested in datastores, and for my game i need to save multiple things. Tables came to my mind.

It did not work.

"Does anyone out there know how to save multiple data in one script?"

HERES MY FAILED ATTEMPT TO SAVE MULTIPLE DATA;

the only difference here is on line 35 and 36 and on line 50 and 51.

01-- services --
02 
03local DataStoreService = game:GetService("DataStoreService")
04local SaveGameData = DataStoreService:GetDataStore("SaveGameData")
05 
06-- variables
07 
08local RemoteEvent = game.ReplicatedStorage.RemoteEvent
09 
10-- leaderstats
11 
12game.Players.PlayerAdded:Connect(function(player)
13 
14    local leaderstats = Instance.new("Folder", player)
15    leaderstats.Name = "leaderstats"
View all 66 lines...

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

Hello. You need the name of the dictionary's value. For example, instead of writing SavedGames.Value = Data you'd write SavedGames.Value = Data.Games. Try this:

01-- services --
02 
03local DataStoreService = game:GetService("DataStoreService")
04local SaveGameData = DataStoreService:GetDataStore("SaveGameData")
05 
06-- variables
07 
08local RemoteEvent = game.ReplicatedStorage.RemoteEvent
09 
10-- leaderstats
11 
12game.Players.PlayerAdded:Connect(function(player)
13 
14    local leaderstats = Instance.new("Folder", player)
15    leaderstats.Name = "leaderstats"
View all 70 lines...

Please upvote and accept this answer if it helps.

0
This will work, but you should also add an if statement to see if they actually have data when trying to load, because if a new player joins the game and they don't have any data, it will error. xInfinityBear 1777 — 4y
0
Yes, do that too. youtubemasterWOW 2741 — 4y
0
Okay, thanks for replying! maxpax2009 340 — 4y
0
is it common that it does not work in studio? and i have got API on. maxpax2009 340 — 4y
View all comments (2 more)
0
Yes, it is common. youtubemasterWOW 2741 — 4y
0
Okay, thanks! No wonder you have so much reputation. maxpax2009 340 — 4y
Ad

Answer this question