Twitter Code Gui

Ok, the first thing you want to do is establish valid codes, you can do that by adding a series of stringValues in a folder in replicatedstorage, then you can add a script like this one in the textbox.

script.Parent.FocusLost:Connect(function()
	local text = script.Parent.Text
	for i , v in pairs(game.ReplicatedStorage.Folder:GetChildren()) do
		if v:IsA("StringValue") then
			if string.match(text , v.Value) then
				print("code redeemed")
			end
		end
	end
end)

ik but how to make it be used only once

make a local table with the codes inputted so far and add an additional for loop with an if statement to check if said code has been inputted already.

You can do this try it:

local codes = {
    "CodeHere";
    "Code2Here";
    "CodeAgain"
}

local textBox = --whereever it is located

for _, code in pairs(codes) do
    if textBox.Text == code then
        table.remove(codes,code)
        --rest of code here
    end
end
1 Like

but how to save so they dont use more than once

1 Like

saaving it to datastore, like this

local DataStoreService = game:GetService("DataStoreService")
local codeStore = DataStoreService:GetDataStore("PlayerCodes")
local codes = {
  [1] =  "CodeHere";
   [2] = "Code2Here";
    [3] ="CodeAgain"
}
if not codestore:GetAsync(Player.Name) then
codestore:SetAsync(codes)
end
local textBox = --whereever it is located

for _, code in pairs(codestore:SetAsync(codes)) do
    if textBox.Text == code then
        table.remove(codestore:SetAsync(codes),code)
        --rest of code here
    end
end

if there is no past registry of codes the player inputed, the script adds the list of codes to the datastore.

1 Like

Just listen to @b0r_4li5 he is telling you what to do.

  1. have a Textbox on the client where the player inputs code
  2. fire remote function to the server with the inputted code
  3. check if the code is a valid code (search a table or something)
  4. check if the user already redeemed the code, by checking a datastore (an easy way is to make the key the code and just have a bool value)
  5. if they haven’t redeemed the code, then set the datastore value to true
  6. give them a prize and return true to the RemoteFunction so the client can display UI
1 Like

I watched this video (Roblox Scripting Tutorial: How to Script Twitter Codes - YouTube) now I know how to save the codes but how would I let the code be reused when i let it be reused so its one time use but then i let it be reused

datastore

How do I let the code be reused

not datastore

Then just dont do datastore loll

1 Like

Or change their value manually

in conclusion: datastore

(thank you roblox for making me type this out 30)

What if i do a code for christmas “Gift” and then for next christmas they cannot use it because it is saved in ds (and i want it to be used once per year)

I know BUT I want some codes to be reused once per year

So put a unique tag on each code, because if you wanted to reset it once per year, you don’t know if it’s from this year or last year.

So in each save to the key a tag or make the key a unique tag like “TwitterCode-2021”

wdym tag? its a string value or intvalue?

Or better idea, use a different datastore for each year

Example:

you have a Datastore called “2021” then save the codes to that.

Then in 2022 save the codes to a datastore “2022”, that way you won’t run into the problem of knowing which year it’s from.


I would do the latter example, but I guess if you really want when you release the update with the code for the new year erase the code from the datastore when they join. So everyone has a blank slate. That will work as long as you don’t do it when the player is redeeming a code.

Similarly-(ish?) I would just for the easier approach and just make each years code like

Ex: Gift2021, Gift2022, etc

not exactly “resuable” but good enough