Hi guys, I am making a datastore system using datastore 2 module. The game I’m working on has a car system and I need to save the list of cars bought, anyone know how to add it to my script?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DataStore2 = require(script:WaitForChild("DataStore2"))
local DataVars = {
["Cash"] = 100,
["Hunger"] = 100,
["Level"] = 1,
["XP"] = 0
}
function addPlayer(player)
local DataFolder = Instance.new("Folder",player)
DataFolder.Name = "Data"
--Loop to make rep amounts
for key, defaultval in pairs(DataVars) do
local keystore = DataStore2(key, player)
local RepAmt = Instance.new("NumberValue",DataFolder)
RepAmt.Name = key
local function UpdateRepAmt(RepAmt)
RepAmt.Value = keystore:Get(defaultval)
end
UpdateRepAmt(RepAmt)
keystore:OnUpdate(UpdateRepAmt(RepAmt))
print(key.." loaded")
end
end
for _,player in pairs(Players:GetPlayers())do
addPlayer(player)
end
Players.PlayerAdded:connect(addPlayer)