Requesting help with a twitter code system!

Hey developers! So I’m trying to make a twitter code system for my simulator right now and I’m having a bit of a problem whenever I redeem a code, it’s not with incrementing the values or anything or saving used codes, those work fine. The problem lies within the text box I’m using for the player to type the code. You see, I tried to code it so that when the player redeems a fresh code, it says “code successfully redeemed” and when they attempt to redeem an invalid code, it says “invalid code”. I’ve noticed even when redeeming a fresh code, it says invalid. The system for displaying the successful and unsuccesful phrases are simply just returning true or false. I will provide a video of my problem and the code on both client and server. Your help would be greatly appreciated! :slight_smile:

Video
robloxapp-20201030-2305525.wmv (591.3 KB)

Client Code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Enter = script.Parent.Enter
local Submitter = script.Parent.Submitter
local CodeEvent = ReplicatedStorage:WaitForChild("Code")

Submitter.MouseButton1Click:Connect(function()
	local CodeEntered = Enter.Text
	local ServerFire = CodeEvent:FireServer(CodeEntered)
	
	if ServerFire == true then
		Enter.Text = ""
		Enter.PlaceholderText = "Redeemed Code!"
		wait(1)
		Enter.PlaceholderText = "Enter Code Here!"
	else
		Enter.Text = ""
		Enter.PlaceholderText = "Invalid Code Entered, Check Again!"
		wait(1)
		Enter.PlaceholderText = "Enter Code Here!"
	end
end) 

Server Code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CodeEvent = ReplicatedStorage:WaitForChild("Code")
local DataStoreService = game:GetService("DataStoreService")

local Codes = {
	Tofuu = {"Taps", 1000},
	Russo = {"Taps", 1000},
	Release = {"Taps", 5000},
	FollowConstride = {"Taps", 1000},
	FreeCoins = {"Coins", 500},
	OneRebirth = {"Rebirths", 1},
	Avi = {"Taps", 1500},
	DaddyDob = {"Taps", 1000},
	GoodBuilderAyzilo = {"Taps", 1000},
	YuriikaiNoob = {"Taps", 1000},
	Krazy3K = {"Taps", 3000},
	Cam = {"Coins", 1200},
	DrakeCraft = {"Taps", 1000},
	CalebRylan = {"Coins", 1500},
}

CodeEvent.OnServerEvent:Connect(function(Player, CodeEntered)
	local CodeStore = DataStoreService:GetDataStore("ResetCodeStore"..CodeEntered)
	local RedeemedCodes = CodeStore:GetAsync(Player.UserId)
	
	if Codes[CodeEntered] and not RedeemedCodes then
		local RewardCategory = Codes[CodeEntered][1]
		local Reward = Codes[CodeEntered][2]
		local Value = Player.StatsFolder[RewardCategory]
		
		Value.Value = Value.Value + Reward
		CodeStore:SetAsync(Player.UserId, true)
		return true
	else
		return false
	end
end)

Once again your help would be appreciated, thanks!

2 Likes

Line 24 appears to be the cause of the problem. You’re not checking if the code is redeemed in the second part of your conditional. You’re checking if RedeemedCodes, as in the table, exists. I think you intended for something like this?

if Codes[CodeEntered] and not RedeemedCodes[CodeEntered] then
    ...
end
1 Like

You can’t use a RemoteEvent to return a value, replace it with a RemoteFunction.

2 Likes

Works like a charm, thank you so much! :slight_smile:

1 Like