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

How can I make a Data Store that can save 4-5 values?

Asked by 6 years ago

I dont know how to use Data Store that can save some stats, like exp mana, maxhealth, level, maxexpneeded, etc.I am new to Data Store so if someone can help me with this, I will be thankfully.The values are IntValues

2 answers

Log in to vote
0
Answered by
F_F 53
6 years ago

Firstly, you would need to acquire DataStoreService and save the Data inside a table. Secondly, you will look through the DataStore where you are saving data if any Data is found you will use SetAsync to represent it otherwise the default.

local DataStore = game:GetService("DataStoreService") local DS1 = DataStore:GetDataStore("PlayerData") -- This is where you will save your data to.

game.Players.PlayerAdded:Connect(function(Player) local User = "user-" .. tostring(Player.UserId) -- Get the player's UserId local Data = Instance.new("Folder", Player) -- Instance a folder inside the Player local Exp = Instance.new("IntValue", Player) -- Instance an IntValue inside the Data folder.

Data.Name = "Data"
Exp.Name = "Exp"

local Save = DS1:GetAsync(user)

if Save then
    Exp.Value = Save[1]
else
    local ProgressToSave = {Exp.Value}
    DS1:SetAsync(user, ProgressToSave )

end)

-- Once the player is leaving the game you want to save their achievements.

game.Players.PlayerRemoving:Connect(function(Player) local User = "user-" .. tostring(Player.userId) local SaveProgress = {Player.Data.Exp.Value} DS1:SetAsync(user, SaveProgress) end)

Hopefully, I helped.

0
Do u have Discord?I need some more help tecady2111 12 — 6y
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

Just store them in a table and save that table to a key. You could also use multiple keys if you wished, but that is inefficient. There is limits to the length of saved data. For more information, click here

0
Thx, ill try tecady2111 12 — 6y

Answer this question