-
What do you want to achieve? I want to make a datastore that can store multiple values. Right now, it is not storing anything.
-
What is the issue? It’s not storing data at all.
-
What solutions have you tried so far? I tried doing different things, like setting value of data as a table, using different keys, and comparing my datastore with other people’s. It still doesn’t function properly.
Here’s the code:
local currencyDS = DSS:GetDataStore("currencyDS")
game.Players.PlayerAdded:Connect(function(plr)
local currency = Instance.new("Folder")
currency.Name = "Currency"
currency.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = currency
local playerUID = "player_" .. plr.UserId
local data = {}
local success, err = pcall(function()
data = currencyDS:GetAsync(playerUID)
end)
if success then
print("Success")
if data then
print("data collected")
cash.Value = data[1]
else
cash.Value = 0
end
else
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local currency = plr.Currency
local cash = currency.Cash
local data = {
cash.Value
}
local playerUID = "player_" .. plr.UserId
local success, err = pcall(function()
currencyDS:SetAsync(playerUID)
end)
if success then
print("data saved")
else
warn(err)
end
end)