im trying to make a datastore script which stores a players redeemed codes, however, im getting the error unable to cast value to object and i cant find out whats wrong
local DS = game:GetService("DataStoreService"):GetDataStore("Codes")
game.Players.PlayerAdded:Connect(function(player)
wait()
local plrKey = "id_"..player.UserId
local getSaved = DS:GetAsync(plrKey)
if getSaved then
for i, v in pairs(getSaved) do
local temp = Instance.new("BoolValue", player.Codes)
temp.Name = v
end
else
local ValuesForSaving = {}
for i, v in pairs(player.Codes:GetChildren()) do
table.insert(ValuesForSaving, v.Name)
end
DS:GetAsync(plrKey, ValuesForSaving) -- problematic line
end
end)
game.Players.PlayerRemoving(function(player)
local savevalues = {}
for i, v in pairs(player.Codes:GetChildren()) do
table.insert(savevalues, v.Name)
end
DS:GetAsync("id_"..player.UserId)
end)