Code Door Not Working In Game

I have a code door but it only works in studio not the actual game.
In the actual game, it doesn’t let me click the buttons.

Studio footage:
https://i.gyazo.com/374d121043d0ccc1a93d524fa69b4f82.mp4

Roblox footage:
https://i.gyazo.com/7df068a0e709f12c9a2662ead84a44de.mp4

Door code:

local airlockDoor = script.Parent.AirlockDoor
local sound = script.Parent.AirlockDoor.DoorMain.DoorHinge.Sound
local buttonSound = script.Parent.Frame.KeypadSound.Sound
local configs = script.Parent.Configurations
local doorOpen = false
local code = math.random(1,1000)
local nums = {"1","2","3","4","5","6","7","8","9","0"}
local input = {}
local display = script.Parent.Display.SurfaceGui.TextBox

game:GetService("Workspace").CodePart.SurfaceGui.TextLabel.Text = code
print(code)

buttonSound.SoundId = configs.ButtonSound.Value

function closeAirlock()
	for i = 1, 80 do
		airlockDoor.DoorTop:SetPrimaryPartCFrame(airlockDoor.DoorTop.PrimaryPart.CFrame * CFrame.new(0,-0.05,0))
		airlockDoor.DoorBottom:SetPrimaryPartCFrame(airlockDoor.DoorBottom.PrimaryPart.CFrame * CFrame.new(0,0.05,0))
		airlockDoor.DoorMain:SetPrimaryPartCFrame(airlockDoor.DoorMain.PrimaryPart.CFrame * CFrame.new(-0.05,0,0))
		wait()	
	end
	sound.SoundId = configs.CloseSound.Value
	sound:Play()
	for i = 1, 60 do
		airlockDoor.DoorTop:SetPrimaryPartCFrame(airlockDoor.DoorTop.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(1.5)))
		airlockDoor.DoorBottom:SetPrimaryPartCFrame(airlockDoor.DoorBottom.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-1.5)))
		wait()	
	end
	doorOpen = false
end

function openAirlock()
	doorOpen = true
	sound.SoundId = configs.OpenSound.Value
	sound:Play()
	for i = 1, 60 do
		airlockDoor.DoorTop:SetPrimaryPartCFrame(airlockDoor.DoorTop.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-1.5)))
		airlockDoor.DoorBottom:SetPrimaryPartCFrame(airlockDoor.DoorBottom.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(1.5)))
		wait()	
	end
	for i = 1, 80 do
		airlockDoor.DoorTop:SetPrimaryPartCFrame(airlockDoor.DoorTop.PrimaryPart.CFrame * CFrame.new(0,0.05,0))
		airlockDoor.DoorBottom:SetPrimaryPartCFrame(airlockDoor.DoorBottom.PrimaryPart.CFrame * CFrame.new(0,-0.05,0))
		airlockDoor.DoorMain:SetPrimaryPartCFrame(airlockDoor.DoorMain.PrimaryPart.CFrame * CFrame.new(0.05,0,0))
		wait()	
	end
	wait(configs.OpenTime.Value)
	closeAirlock()
end

function updateScreen()
	local currentDisplay = table.concat(input)
	if #input < string.len(code) then
		repeat
			display.Text = currentDisplay .. "-"
			currentDisplay = display.Text
			wait()
		until string.len(display.Text) == string.len(code)
	else
		display.Text = currentDisplay
	end
end

updateScreen()

for i, v in pairs(script.Parent.KeyPad:GetChildren()) do
	v.ClickDetector.MouseClick:Connect(function()
		if v.Name == "Enter" and doorOpen == false then
			buttonSound:Play()
			if tonumber(table.concat(input)) == code  then
				display.Text = "CORRECT"
				input = {}
				spawn(openAirlock)
				wait(2)
				display.Text = ""
				updateScreen()
			else
				display.Text = "WRONG"
				input = {}
				wait(2)
				display.Text = ""
				updateScreen()
			end
		elseif v.Name == "Enter" and doorOpen == true then
			buttonSound:Play()
			display.Text = "WAIT"
			input = {}
			wait(2)
			display.Text = ""
			updateScreen()
		elseif v.Name == "Exit" and doorOpen == false then
			buttonSound:Play()
			openAirlock()
		elseif v.Name == "Delete" then
			buttonSound:Play()
			input = {}
			updateScreen()
		--else
			--for i = 1, 10 do
				elseif tonumber(v.Name) then
					buttonSound:Play()
					if #input >= string.len(code) then
						table.remove(input, 1)
					end
					table.insert(input, v.Name)
					updateScreen()
				--end
			--end
		end
	end)
end
2 Likes

If something does not function correctly in the actual game, then maybe you haven’t published the game. Have you published the game and then joined a new server?

Yes i have otherwise I wouldn’t be able to play the actual game anyway

Go to “drafts” In the “view” tab, and right click each script there and press “Commit”

Good idea. ROBLOX had recently made that the default.

I wish they hadn’t, is there a way to select all the scripts at once in the drafts page, instead of going through each one?

There are no scripts there; it just says empty.

image

Perhaps you could go into settings and disable Collaborative Script Editing?

You should disable Collaborative Editing in Game Settings or just not use team create.

Team Create automatically saves the place so in case the OP’s internet goes down all of his changes aren’t lost

If your internet goes down, you don’t disconnect when not using team create. You should always (regularly) save your work anyway; both TC and standard will autosave regularly and create recovery files in the event of an unexpected stop.

i wasn’t using team create anyway but I just turned it on just now so I could access “drafts”

I was looking, and saw that your checking the string.len of a number value. Another thing, your code is not guaranteed to be 4 characters long. If you want a 4 digit number then you must change the math.random to be 1000,9999
Also make sure you tostring the code because of the string.len

I don’t want a 4 digit number. I just want any number between 1 and a thousand.