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

Help with this code script that is not working?

Asked by 8 years ago

I'm trying to make this script with codes and if the player types in any of the code then the code Value will be set to 1 and it seems to me that its not working. Any suggestions or tips for me to fix this script? Thank you for your time!

local deb = false
local code =   "Code1" , "Code2" --list of codes here that I wrote
local txtBox = script.Parent.Parent:WaitForChild("TextBox")
local CodeHolder = game.Players.LocalPlayer.Codes:FindFirstChild("Code1","Code2") --String values in players
script.Parent.MouseButton1Click:connect(function()
    local plr = game.Players.LocalPlayer
    if txtBox.Text == code and deb == false then --- I wrote this so that it will work if it finds matching code names
        CodeHolder.Value = "1" 
        deb = true
        txtBox.Text = "Code Accepted!"
    else
        txtBox.Text = "Invalid Code"
    end
end)

1 answer

Log in to vote
1
Answered by 8 years ago

You have multiple issues.

First off, on line 2, you need to use a table. If you want to associate multiple values with one variable, you use tables. Tables are like boxes -- you have a box labeled "Codes", and then all of the items inside the box are individual codes. The syntax for tables is: local codes = {"Code1", "Code2"}

The second issue is that you have is you're using FindFirstChild wrong. I'm not entirely sure what you're trying to do, but FindFirstChild only takes one parameter (well, that's not entirely true -- it does have a second parameter, but that's to toggle whether the search is recursive or not -- not to search for multiple objects. It isn't something you need to worry over right now, so just pretend it only accepts one parameter.) If you have two separate frames, one for code1 and one for code2, you'd need to do:

local CodeHolder1 = game.Players.LocalPlayer.Codes:FindFirstChild("Code1")
local CodeHolder2 = game.Players.LocalPlayer.Codes:FindFirstChild("Code2")

What exactly are you trying to do with this though? Could you explain it a bit better? I can't tell based off of your description or code.

Ad

Answer this question