Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Code gui isn't working properly?

Asked by
Relatch 550 Moderation Voter
9 years ago

This code gui works perfectly, but I redeemed my code, and I put in a code that didn't exist, but it still said "Already Redeemed!" Any ideas why?

local box = script.Parent.Parent.CodeBox
local plr = script.Parent.Parent.Parent.Parent
local redeemed = false

box.FocusLost:connect(function()
    if box.Text == "Points" and redeemed == false then
        redeemed = true
        box.Text = "Code Accepted!"
        plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50
        wait(1)
        box.Text = "Redeem Code"
    elseif redeemed == true then
        box.Text = "Already Redeemed!"
        wait(1)
        box.Text = "Redeem Code"
    else
        box.Text = "Code Declined!"
        wait(1) 
        box.Text = "Redeem Code"
    end
end)

1 answer

Log in to vote
2
Answered by
Mystdar 352 Moderation Voter
9 years ago

It is because once you have redeemed it, 'redeemed' is now true, so on line 12, you're saying regardless of what they put because it has already been redeemed you are acting as though they put the correct code in, to fix this change line 12 to:

elseif box.Text == "Points" and redeemed == true then

What line 12 is saying now is, if they put the correct code in (in this instance I presume the code is "Points") and they have already redeemed it then (do, etc)

As a side note instead of writing

if redeemed == true then

You can just do:

if redeemed then

This applies for false statements too: (Before)

if redeemed == false then

(After)

if not redeemed then
0
Thanks! :D Relatch 550 — 9y
0
Updated Mystdar 352 — 9y
Ad

Answer this question