Having Problems with Datastore

I am new to DataStore services and I am trying to create a Redeemable Code System but I encountered a bug I can’t figure out how to fix.

local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData")
local Data

local Codes = require(game.ReplicatedStorage:WaitForChild("Codes").Module)

local CodesFrame = script.Parent.CodesFrame
local CodesTextBox = CodesFrame.Codes.Frame.TextBox
local RedeemButton = CodesFrame.Codes.Redeem

local Cooldown = 1
local now = tick() 

game.Players.PlayerAdded:Connect(function(player)
	local Player_ID = "Player_" .. player.UserId

	local Success,err = pcall(function()
		Data = Datastore:GetAsync(Player_ID)
	end)

	if not Success then error(err) end

	if not Data then
		Data = {RedeemedCode = {}}
	end
end)

game.ReplicatedStorage.Codes.Outcome.OnServerEvent:Connect(function(player, input)
	if tick() - now <= Cooldown then return end
	now = tick()

	if Codes[input] then
		if not player:IsInGroup(12814180) then
			game.ReplicatedStorage.Codes.Outcome:FireClient(player, "Not in Group!")
		elseif not table.find(Data.RedeemedCode,input) then
			table.insert(Data.RedeemedCode,input) -- This is where the problem is
			coroutine.wrap(Codes[input])(player)

			game.ReplicatedStorage.Codes.Outcome:FireClient(player, "Redeemed Code!")

			local success,err = pcall(Datastore.UpdateAsync, Datastore, "Player_" .. player.UserId, function(old)
				return Data
			end)            
			if not success then error(err) end
		else
			game.ReplicatedStorage.Codes.Outcome:FireClient(player, "Already Redeemed Code!")
		end
	end
end)

Did you go to Game Settings → Security → enable access to api services?

Yes. That is clearly not the issue, or else the output would had a different error.

game.ReplicatedStorage.Codes.Outcome.OnServerEvent:Connect(function(player, input)
	if tick() - now <= Cooldown then return end
	now = tick()
    print(Data)

If you add a print statement at the end of the remote event function does it print anything?

Data is nil, I think that might be the problem.

Is the playerAdded function being called? If there is any yield before the playerAdded connection is connected it could cause it to not run if the player joins before it is called.