Help with a redeeming code system

So I’m making a code redeeming system, where you press a textbutton, it fires a remote event, the remote event activates a server script in serverscriptservice, and if the code is valid, it will give you the reward, and if it is not valid, it will not redeem. However, I am having some problems with the script. I assume it is to deal with the if then statement. I have not had any errors, and the text only changes with the “Code Not Valid!” in the end of the script. I would appreciate any help with this.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local used = game.ServerScriptService:WaitForChild("DataStorer_DataStore"):WaitForChild("SaveData"):WaitForChild("CodeUsed")
local remoteEvent = ReplicatedStorage:WaitForChild("codeEvent")
local reward = game.ServerScriptService:WaitForChild("DataStorer_DataStore"):WaitForChild("SaveData"):WaitForChild("Reward")
local code = game.ServerScriptService:WaitForChild("DataStorer_DataStore"):WaitForChild("Codes"):WaitForChild("WorkingCode")
game.Players.PlayerAdded:Connect(function(player)
	local enterbutton = player:WaitForChild("PlayerGui"):WaitForChild("CodeGUI").CodesFrame.EnterCode
	local textbox = player:WaitForChild("PlayerGui"):WaitForChild("CodeGUI").CodesFrame.TextBox


local function onEnterCode(player)
		print("RemoteEvent recieved")
	if textbox.Text == code.Value then
		if used.Value == false then
			player.leaderstats.Points.Value += reward.Value
			enterbutton.Text = "Code Redeemed!"
			print("Code Redeemed!")
			used.Value = true
			wait(2)
			enterbutton.Text = "Enter"
		else
			enterbutton.Text = "Code Already Redeemed!"
			wait(2)
			enterbutton.Text = "Enter"
		end
	else
			enterbutton.Text = "Code Invalid!"
			wait(2)
			enterbutton.Text = "Enter"
		end
	end

		
remoteEvent.OnServerEvent:Connect(onEnterCode)	
end)

Your are checking obj.Text on the Server, when a player types something in the textbox it only shows for the client, not the server.

I recommend making the textbox localscript to pass string (obj.Text) with :FireServer().
Also the game.Players.PlayerAdded:Connect() is not needed for the remoteEvent, since roblox’ already returns a default (the player who fired it) playerOBJ when it is fired.

How would I go about doing this? Should a put a local script into the enter button that fires a remote event? How would this be any different from what I’m doing?

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