I have a script that's supposed to get password input from a remote event (works fine) and if the password matches one from the table it gets the place id of the password and returns a value true or false depending on if the password was right.
Example:
re:FireClient(plr,false) -- password wasn't correct re:FireClient(plr,true) -- password was correct
Any help is appreciated!
My code is here:
local TpService = game:GetService("TeleportService") local re = game.ReplicatedStorage["HelloScripters!!"] local passwords = {} -- Passwords -- passwords["12 15 05"] = {} passwords["15 15 25"] = {} -- Password place IDs -- passwords["12 15 05"].id = "8346845291" passwords["15 15 25"].id = "2548213281" print(passwords) local function tpTo(ID,PLAYER) TpService:Teleport(ID,PLAYER) end re.OnServerEvent:Connect(function(plr,password) print("Received password input by "..plr.Name..". Entered password: "..password) local success = false local brr local thing = table.find(passwords,password) -- doesnt find it and returns nill even if the password exists print(thing) --[[ for i,thing in pairs(passwords) do if thing.Name == password then brr = thing end end ]] if brr then local id = brr.id if id then success = true print("Info: Password & ID found! Password: "..brr.." ID: "..id) else print("DANGER: No ID for password: "..brr) end else print("Warning: Incorrect or non-existing password.") end --[[ for i, bruh in ipairs(passwords) do if bruh == password then success = true print(bruh) print(bruh.id) re:FireClient(plr,true) tpTo(bruh.id,plr) end end ]] if success == false then re:FireClient(plr,false) else re:FindClient(plr,true) end end)
The reason why it's not finding the password is because you have the password set to the index, not the value. The table.find function is trying to find a value inside the passwords table and because there is no value of "12 15 05" and "15 15 25" it is returning nil.
To fix this, you don't really need to use a for loop in this case, you can just do if passwords[password] then ...
this will return the value of the index, which you can use to determine if it's there or not.
Also, I recommend using a RemoteFunction if you need to return a value back, a RemoteFunction will wait for a response, in this case, it would be whether this was successful or not.