-
What do you want to achieve?
So, I have a codes GUI that adds a BoolValue into a folder inside the player when they redeem the code. I want to save that codes that are inside the folder so they can’t redeem them again but don’t know how to. -
What is the issue?
The way I scripted it is not working. (Don’t know much about DataStores) -
What solutions have you tried so far?
I tried using :GetChildren() but that doesn’t seem to work
Note: I commented the parts that I tried to save codes
local Data = game:GetService("DataStoreService"):GetDataStore("Test1")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Plr)
local Statistics = Instance.new("Folder")
Statistics.Name = "leaderstats"
Statistics.Parent = Plr
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = Statistics
local Codes = Instance.new("Folder") -- Codes Folder
Codes.Name = "Codes"
Codes.Parent = Plr
local codesToSave = Codes:GetChildren() -- Get Codes In Folder
local uniqueKey = "id-"..Plr.UserId
local getSaved = Data:GetAsync(uniqueKey)
if getSaved then
Cash.Value = getSaved[1]
else
local valuesToSave = {
Cash.Value,
codesToSave, -- Codes
}
Data:SetAsync(uniqueKey, valuesToSave)
end
end)
Players.PlayerRemoving:Connect(function(Plr)
local uniqueKey = "id-"..Plr.UserId
local valuesToSave = {
Plr.leaderstats.Cash.Value,
Plr.Codes:GetChildren(), -- Codes
}
Data:SetAsync(uniqueKey, valuesToSave)
end)