I decided to add another code to my gui, the first code (Points) works great. The second, not so much. I put in "MorePoints", and it does nothing at all. It just says "MorePoints". Any ideas as to why this is happening? I'm also getting no errors whatsoever.
local box = script.Parent.Parent.CodeBox local plr = script.Parent.Parent.Parent.Parent local redeemed = false box.FocusLost:connect(function() if box.Text == "Points" or "MorePoints" and redeemed == false then if box.Text == "Points" then redeemed = true box.Text = "Code Accepted!" plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50 wait(1) box.Text = "Redeem Code" elseif box.Text == "MorePoints" then redeemed = true box.Text = "Code Accepted!" plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 100 wait(1) box.Text = "Redeem Code" elseif box.Text == "Points" or "MorePoints" and redeemed == true then box.Text = "Already Used!" wait(1) box.Text = "Redeem Code" else box.Text = "Code Declined!" wait(1) box.Text = "Redeem Code" end end end)
marcoantoniosantos3 fixed up your 'if' statements correctly. If the first thing you type is "MorePoints", does it work?
I expect that what's happening is that you're expecting to be able to type in "Points" and then "MorePoints" after that, but the script is rejecting that because "redeemed" is already "true".
The solution is to have another variable, like "morePointsRedeemed". If you plan on having more than two of these lines, you should switch to lists and dictionaries:
validCodes = {"Points", "MorePoints"} --expand as desired redeemed = {} --Dictionary; key is code, value is true for redeemed or nil for not redeemed redeemFunction = { function() plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50 end, --Points function() plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 100 end --MorePoints } --expand as desired to mirror the "validCodes" list (so that the first function redeems the first code in the list, etc.) local box = script.Parent.Parent.CodeBox local plr = script.Parent.Parent.Parent.Parent box.FocusLost:connect(function() local validCode = false local functionToUse = nil --the function to call to redeem the code for i = 1, #validCodes do if box.Text == validCodes[i] then validCode = true functionToUse = redeemFunction[i] break end end if validCode then if not redeemed[box.Text] then redeemed[box.Text] = true box.Text = "Code Accepted!" functionToUse() wait(1) box.Text = "Redeem Code" else box.Text = "Already Used!" wait(1) box.Text = "Redeem Code" end else box.Text = "Code Declined!" wait(1) box.Text = "Redeem Code" end end)
Not sure about this fix but:
local box = script.Parent.Parent.CodeBox local plr = script.Parent.Parent.Parent.Parent local redeemed = false box.FocusLost:connect(function() if (box.Text == "Points" or box.Text == "MorePoints") and redeemed == false then if box.Text == "Points" then redeemed = true box.Text = "Code Accepted!" plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50 wait(1) box.Text = "Redeem Code" elseif box.Text == "MorePoints" then redeemed = true box.Text = "Code Accepted!" plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 100 wait(1) box.Text = "Redeem Code" elseif (box.Text == "Points" or box.Text == "MorePoints") and redeemed == true then box.Text = "Already Used!" wait(1) box.Text = "Redeem Code" else box.Text = "Code Declined!" wait(1) box.Text = "Redeem Code" end end end)