Functions Not Calling

So I made a script that opens a door when you enter the correct code, however I am entering the correct code. But it’s not working. It doesn’t even print out the numbers, so that’s how I know it isn’t working.

It only registers as DENIED. That’s because it never got a code, (0000) so now it’s just registering the enter button.

local door = workspace.door
local main = script.Parent.main
local numfolder = script.Parent.numbers
local zero = numfolder.zero
local one = numfolder.one
local two = numfolder.two
local three = numfolder.three
local four = numfolder.four
local five = numfolder.five
local six = numfolder.six
local seven = numfolder.seven
local eight = numfolder.eight
local nine = numfolder.nine
local clear = main.clear
local enter = main.enter
                              --Number Variables
----------------------------------------------------------------------------------------------------------------
                             

code = "0000"
input = ""
                              --Main Variables
----------------------------------------------------------------------------------------------------------------
                              --Main Functions       

function Clear()
	input = ""
	print("Cleared")
end

clear.ClickDetector.MouseClick:Connect(Clear)

function Enter()
	if input == "0000" then
		print("Entered")
		door.Transparency = 1
		door.CanCollide = false
		wait(10)
		door.Transparency = 0
		door.CanCollide = true
		enter["door open metal"]:Play()
	else
		print("Denied")
		enter["Access Denied"]:Play()
	end
end

enter.ClickDetector.MouseClick:Connect(Enter)

while wait(0.1) do
	main.IPInterface.inputGUI.inputField.Text = input
end
----------------------------------------------------------------------------------------------------------------
                              --Button Script
function zero()
	input = input..0
	print(input)
end

function one()
	input = input..1
	print(input)
end

function two()
	input = input..2
	print(input)
end

function three()
	input = input..3
	print(input)
end

function four()
	input = input..4
	print(input)
end

function five()
	input = input..5
	print(input)
end

function six()
	input = input..6
	print(input)
end

function seven()
	input = input..7
	print(input)
end

function eight()
	input = input..8
	print(input)
end

function nine()
	input = input..9
	print(input)
end

zero.ClickDetector.MouseClick:Connect(zero)
one.ClickDetector.MouseClick:Connect(one)
two.ClickDetector.MouseClick:Connect(two)
three.ClickDetector.MouseClick:Connect(three)
four.ClickDetector.MouseClick:Connect(four)
five.ClickDetector.MouseClick:Connect(five)
six.ClickDetector.MouseClick:Connect(six)
seven.ClickDetector.MouseClick:Connect(seven)
eight.ClickDetector.MouseClick:Connect(eight)
nine.ClickDetector.MouseClick:Connect(nine)

Help!

1 Like

You are concatenating numbers when the input is a string, which is why it isn’t working. Convert the numbers into a string before concatenating them to the input string

1 Like

Spawn the while loop as well

spawn(function()
         main.IPInterface.inputGUI.inputField.Text = input
end
1 Like

This is a little confusing, could you explain sorry?

1 Like

Context : Concatenating is the process of seamlessly joining two data types of the same type (eg. a string)
Your mistake here is that you are trying to concatenate a number (0-9) to input which is a string (“0728”). A string has quotation while numbers don’t. Which is why your numbers aren’t concatenating to input

1 Like

These variable and function collide with each other rename either of these.


Use ..= compound assignment..

There was some errors that broke your code.

The first one being the loop to update input text, a while ... do loop is yielding the code, so everything bellow the loop will never be runned unless you’re stopping the loop using break.

The second is that you have to choose if the input is a number or a string value. You first set it as a string but updated it as a number when pressing buttons.


Could you try this?

local door = workspace.door
local main = script.Parent.main
local numfolder = script.Parent.numbers

local clear = main.clear
local enter = main.enter
local numinputs = {
	zero = "0";
	one = "1";
	two = "2";
	three = "3";
	four = "4";
	five = "5";
	six = "6";
	seven = "7";
	eight = "8";
	nine = "9"
}

----------------------------------------------------------------------------------------------------------------
code = "0000"
input = ""

----------------------------------------------------------------------------------------------------------------
--Main Functions       
function Clear()
	input = ""
	print("Cleared")
end

function Enter()
	if input == "0000" then
		print("Entered")
		door.Transparency = 1
		door.CanCollide = false
		wait(10)
		door.Transparency = 0
		door.CanCollide = true
		enter["door open metal"]:Play()
	else
		print("Denied")
		enter["Access Denied"]:Play()
	end
end

local function UpdateInput(numpart)
	input ..= numinputs[numpart.Name]
	main.IPInterface.inputGUI.inputField.Text = input
	print(input)
end

----------------------------------------------------------------------------------------------------------------
--Clicks
enter.ClickDetector.MouseClick:Connect(Enter)
clear.ClickDetector.MouseClick:Connect(Clear)

for _, numpart in numfolder:GetChildren() do
	if numpart:FindFirstChildWhichIsA("ClickDetector") then
		numpart.ClickDetector.MouseClick:Connect(function()
			UpdateInput(numpart)
		end)
	end
end

I feel this needs clearing up and its important to it

The numbers are buttons. That is why they are named like that.