Datastore is not saving

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want my datastore to save

  1. What is the issue? Include screenshots / videos if possible!

It doesn’t save

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I cannot find any solution

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

```lua
local DataStoreService = game:GetService("DataStoreService")
local RedeemDataStore = DataStoreService:GetDataStore("RedeemDataStore")
local Config = require(script.Parent)

local function hasRedeemedCode(player, enteredCode)
	local redeemedCodeKey = "RedeemedCodes_" .. player.UserId .. "_" .. enteredCode
	local hasRedeemed, err = RedeemDataStore:GetAsync(redeemedCodeKey)
	return hasRedeemed, err
end

local function redeemCode2(player, enteredCode)
	local hasRedeemed, err = hasRedeemedCode(player, enteredCode)

	if hasRedeemed then
		print("You have already redeemed this code.")
		return
	end

	local codeData = Config.Code[enteredCode]

	if codeData then
		if codeData.Type == "Tool" then
			local toolName = codeData.Value
			local tool = script.Parent.Parent:FindFirstChild("Cards"):FindFirstChild(toolName)

			if tool then
				local backpack = player.Backpack
				local toolClone = tool:Clone()
				toolClone.Parent = backpack
				print("Code redeemed successfully! You received the tool:", toolName)
				tool:Destroy()
			else
				print("The tool corresponding to this code does not exist.")
			end
		elseif codeData.Type == "leaderstats" then
			local leaderstats = player:FindFirstChild("leaderstats")

			if leaderstats then
				local statName = codeData.Value
				local amountToAdd = codeData.Amount or 0

				local statValue = leaderstats:FindFirstChild(statName)
				if statValue then
					statValue.Value = statValue.Value + amountToAdd
				else
					local newStatValue = Instance.new("IntValue")
					newStatValue.Name = statName
					newStatValue.Value = amountToAdd
					newStatValue.Parent = leaderstats
				end

				print("Leaderstat redeemed successfully! Added", amountToAdd, "to", statName)
			else
				print("Player's leaderstats not found.")
			end
		else
			print("Invalid code type. Please check the configuration.")
		end

		local redeemedCodeKey = "RedeemedCodes_" .. player.UserId .. "_" .. enteredCode
		RedeemDataStore:SetAsync(redeemedCodeKey, true)
	else
		print("Invalid code. Please try again.")
	end
end

script.Parent.Parent.RemoteEvents.Redeem.OnServerEvent:Connect(function(player, enteredCode)
	redeemCode2(player, enteredCode)
end)

local cardsfolder = script.Parent.Parent.Parent.MilesSystem.Cards
local platinum = cardsfolder:WaitForChild(Config.Platinum)
local DataStoreService = game:GetService("DataStoreService")



script.Parent.Parent.RemoteEvents.Buy.OnServerEvent:Connect(function(player)
	local miles = player.leaderstats.Miles
	local clonetool = platinum:Clone()
	clonetool.Parent = player.Backpack

	local playerData = RedeemDataStore:GetAsync(tostring(player.UserId))

	if playerData then
		playerData.Miles = miles.Value 
	else
		playerData = {Miles = miles.Value} 
	end	


	RedeemDataStore:SetAsync(tostring(player.UserId), playerData)
end)

Redeem data store only saves but Deduct Data store doesn’t