How would I do this?

I’m making a phone number system, I put all the valid numbers in curly brackets {} and named them.

local validNumbers = {
	0101,
	0102,
}

I wanted the system to detect if the number inputted in the phone is one of the valid numbers. This is what I came up with, but it doesn’t seem to work.

if characters == 4 and frame.PhoneNumbers.Text == validNumbers then
			local number = frame.PhoneNumbers.Text
			frame.PhoneNumbers.Text = "Dialing..."
			characters = 0
		elseif characters < 4 or frame.PhoneNumbers.Text ~= validNumbers then
			frame.PhoneNumbers.Text = "INVALID ID"
			wait(2)
			frame.PhoneNumbers.Text = ""
			characters = 0
		end

Could anyone help with another way to approach this?

local validNumbers = {
    0101,
    0102,
}

if table.find(validNumbers, 0101) ~= nil then
    -- valid number
else
    -- invalid number
end

you might want to replace the numbers with strings if you want numbers that start with 0 to not be treated the same as those which dont (i.e. 0101 and 101 are the same number)

1 Like

I ended up fixing the script, by changing the validNumbers to String Values

local validNumbers = {
	"0101",
	"0102",
}

And changing the script to this (the part that detects a correct number)

if characters.Value == 4 and table.find(validNumbers, frame.PhoneNumbers.Text) then
		local number = frame.PhoneNumbers.Text
		frame.PhoneNumbers.Text = "Dialing...."
		game.ReplicatedStorage.Phone.Events.DialNumber:FireServer(number)
		print(number)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.