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

I am trying to make a ATM code system using a for i,v loop but only the first code works???

Asked by
PolyyDev 214 Moderation Voter
7 years ago
Edited 7 years ago

I have written out the code but only the first code in the table works.

01local code = {"2004", "6331"} --Only 2004 works as a code
02local text = script.Parent.Parent.CodeBar
03local val = script.Parent
04local plr = script.Parent.Parent.Parent.Parent.Parent
05 
06print("ATM Loaded")
07 
08script.Parent.MouseButton1Click:connect(function()
09    for i,v in pairs(code) do
10        if text.Text == v then
11            print(plr.Name.." has entered the bank")
12            script.Parent.Parent.Parent.PinCode.Visible = false
13            script.Parent.Parent.Parent.Page1.Visible = true
14        else
15            text.Text = "Incorrect Pin!"
View all 21 lines...
0
local code = {"2004", "6331",} --> to --> local code = {"2004", "6331"} Coasterteam 4 — 7y
0
Oh i'm an idiot, thanks PolyyDev 214 — 7y
0
Actually no, it doesn't work ;-; PolyyDev 214 — 7y
0
Are there any error messages? mustardfoot 90 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I see the error in your script. When you put the code as 6331, it will first check if it says "2004". After seeing it is false, it will set the text to blank two seconds later. After looping, it will then check if the code says "6331", but since you changed the text to become blank, that too will return as false.

Here is a modified version for your script to get it to work.

01local code = {"2004", "6331"}
02local text = script.Parent.Parent.CodeBar
03local val = script.Parent
04local plr = script.Parent.Parent.Parent.Parent.Parent
05 
06print("ATM Loaded")
07 
08script.Parent.MouseButton1Click:connect(function()
09    for i,v in pairs(code) do
10        if text.Text == v then
11            print(plr.Name.." has entered the bank")
12            script.Parent.Parent.Parent.PinCode.Visible = false
13            script.Parent.Parent.Parent.Page1.Visible = true
14            break --Found the code! Breaking the loop.
15        end       
View all 22 lines...
0
Works a charm, thanks dude! PolyyDev 214 — 7y
Ad

Answer this question