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)