Twitter Code Gui

WHAT DO I WANT TO ACHIEVE?

I want to have a code gui that you can press redeem to redeem the code.

HOW DOES IT WORK?

There would be a separate script that handles all the code rewards (in this script you can add and remove codes, make codes automatically expire, and make custom rewards such as give a player a sword give some cash or multiple different currencies)

NOTE: Can only be redeemed once (but can be re-redeemed if allowed)

FINAL:

Pops up a cool notification saying you redeemed…

1 Like

Look on Youtube. There are many tutorials on how to do this.

1 Like

You can use a table with valid codes and use string.match to find out if what was typed in equals a code.

2 Likes

ik but how would i save it so people cannot redeem it more than once

Use datastores :shallow_pan_of_food:

You can use TexBoxes.

Article: TextBox | Roblox Creator Documentation
Scroll down to see how you can achieve this.

ik but how can i save a code to a datastore?

This is easy to do, note that you should not store the codes on the client.
Look it up on YouTube or script your own. You can use a free model if your new to Studio.

1 Like

you just need to save the codes the user has inputted successfully and check them, you can add a metatable and add _index so when the user inputs a valid code that hasn’t been inputted yet you get the message

you know datastores are for leaderstats i am not reallt experienced in the code data

Datastoores are for data persistence in general.

Use a remote function and detect whether the code was valid or not.

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 @boyparis 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