"Reading" through a datastore

Hello, I’m making a twitter code system for a UI and I want it to save so that the player can’t keep redeeming it.

What I have done so far is having it save the code name to the players user ID.

key:GetAsync(plr.UserId.."."..code)

All I need to do is when I have my code check if it’s redeemed I need it to check the data store and see if the code has been saved or not and if it hasn’t it executes.

I’m not sure if this is even possible though.

local DataStoreService = game:GetService("DataStoreService")
local CodeDataStore = DataStoreService:GetDataStore("CodeDataStore")

local code = "some_code"
local player = game.Players.LocalPlayer
local key = player.UserId.."."..code

local success, value = pcall(function() return CodeDataStore:GetAsync(key) end)

if not success or value == nil then
    -- Code has not been redeemed, so execute your code here
else
    -- Code has already been redeemed, so do not execute your code
end

Use this template :+1:

This doesn’t work, it just lets me keep redeeming the code.

You need to do a other one to Async the DataStore corretly, your programmer you could do it.

I have, on the first redeem it saves the data with key:GetAsync(plr.UserId.."."..code) or is that not what you meant?

My code just see if it’s already rendeem.

game.ReplicatedStorage.Codes.OnServerInvoke= function(plr, code)
	local bucks = plr.leaderstats["Lightning Bucks"]
	
	if codes[code] ~= nil then
		local key2 = plr.UserId.."."..code

		local success, value = pcall(function() return key:GetAsync(key2) end)

		if not success or value == nil then
			key:GetAsync(plr.UserId.."."..code)
			bucks.Value += codes[code]
			return "Successfully redeemed "..codes[code].." Lightning Bucks!"
		else
			return "Sadly this code has already been redeemed!"
		end
	end
	
	return "This is an invalid code, are you sure you entered it right?"
end 

This is my code, I’ve implemented everything it needs but it just keep redeeming.

:SetAsync() too need to be implemented to make it work when rendeem

OH MY BAD! I swapped it around my bad.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.