I have a code gui which whenever the player redeems a code it creates a bool value in the code folder and it saves, but whenever I redeem a code it gives a warning that says datatstore request was added to queue, which prevents it from saving...
local data = game:GetService("DataStoreService"):GetDataStore("codes")
game.Players.PlayerAdded:Connect(function(player)
local key = "codes-"..player.userId
local folder = Instance.new("Folder",player)
folder.Name = "Codes"
local save = data:GetAsync(key)
if save then
for i = 1, #save do
local temp = Instance.new("BoolValue",folder)
temp.Name = save[1]
end
end
end)
game.ReplicatedStorage.Remote.Redeem.OnServerEvent:Connect(function(player,code)
local reward = player:FindFirstChild("leaderstats")
local r = reward.Gold
local key = "codes-"..player.userId
if code == "Release" then
if player.Codes:FindFirstChild(code) == nil then
local bool = Instance.new("BoolValue")
bool.Parent = player:FindFirstChild("Codes")
bool.Name = code
r.Value = r.Value + 300
player.PlayerGui:FindFirstChild("SubGui").Code.CodeHandler.Text = "Redeemed!"
wait(3)
player.PlayerGui:FindFirstChild("SubGui").Code.CodeHandler.Text = "Type your code here"
end
end
local activated = {}
for i,v in pairs(player.Codes:GetChildren()) do
if v:isA("BoolValue") then
table.insert(activated, v.Name)
data:SetAsync(key,activated)
end
end
end)
