Help with a door

Hi devs, today i wanted to do a door.

I’ve put a script that makes the textlabel text into a random number for every server using math.random.

So, there is a door, if you put the correct code in the door, you can go through it.(The code you’ve put is showed in the ?? textlabel that you can see in the image)

So, my problem is, when i try to put the code, the textlabel that should say what code i put, is white, clear and enter buttons aren’t working.

These are my scripts:

Script for the door:

local door = script.Parent.Door
local textLabel = script.Parent.Keypad.CodeEntered.SurfaceGui.TextLabel
local clearButton = script.Parent.Keypad.Clear
local enterButton = script.Parent.Keypad.Enter

Instance.new("ClickDetector", clearButton)
Instance.new("ClickDetector", enterButton)

for _, button in ipairs (script.Parent.Keypad.Digits:GetChildren()) do
	Instance.new("ClickDetector", button)
end

local code = ""

local function updateCodeLabel(button)
	textLabel.Text = code
end

local function clearCode()
	code = ""
	updateCodeLabel()
end


local function checkCode()
	if code == script.Parent.Code.SurfaceGui.Code.Text then 
		door.CanCollide = false
		door.Transparency = 0.5
		clearCode() 
	else
		clearCode() 
	end
end

clearButton.ClickDetector.MouseClick:Connect(function()
	clearCode()
end)
enterButton.ClickDetector.MouseClick:Connect(function()
	checkCode()
end)

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	local newText = textLabel.Text
	local lastChar = string.sub(newText, -1)
	if tonumber(lastChar) ~= nil then 
		code = code .. lastChar
		updateCodeLabel()
	end
end)

for _, button in ipairs (script.Parent.Keypad.Digits:GetChildren()) do
	if button:IsA("Part") then
		button.ClickDetector.MouseClick:Connect(function()
			updateCodeLabel(button)
		end)
	else
		print("It's not a part!")
	end
end

Script for the random code:

local textLabel = script.Parent

local randomNumber = math.random(100000000, 999999999)--9
textLabel.Text = randomNumber

Sorry for my bad english.

Thanks!

image

This happens when i click a digit:
image

You will need to create some kind of function/system to display the digit you entered using the keypad, right now your only checking if its pressed at all and then updating it to the code variable, which equals to " ". This is why it shows up as empty.

How do i do this? I tried my best but with no results…

Thanks!

I’d say, add values to each button, and a value into the textLabel that displays the code currently entered, then when they press a button, it copys the current value of the value that is in the textLabel, puts that in, and then adds the value of the button to it. Like this: 1 button pressed: 1, 2 buttons pressed: 11 etc.

Then once they click enter you can just check if the value of the value object under the textLabel is the same as the value generated in the other script.

Then clear would just change the value back to “”

If you are goin to do this, make sure u do not add spaces in the empty value or in the script or anything.

This is most likely not the best solution and there is probs a better solution but it should still work.

There are Videos to make stuff like this. Here is a vid I searched up to help: How to Make a CODE DOOR | HowToRoblox - YouTube

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