I have the following code, it’s for a keypad door, it works almost all the time however rarely some of the buttons that register key inputs don’t work and as such it does not work. No errors are printed when this happens and I don’t know why it does this
code:
local referance = game.Workspace:WaitForChild("Important"):WaitForChild("SecurityRoomDoor"):WaitForChild('Code'):WaitForChild("Thing")
local db = false
local doorStatus = "Closed"
local screen = referance.Parent:WaitForChild("ScreenPart"):WaitForChild("SurfaceGui"):WaitForChild("TextLabel")
local confirm = referance.Parent:WaitForChild("Confirm")
local ProximityPrompt = referance.Parent:WaitForChild("PromptPart"):WaitForChild("CodePrompt")
local cameraPart = referance.Parent:WaitForChild("CameraPart")
local main = referance.Parent.Parent:WaitForChild("Main")
local insideButton = referance.Parent:WaitForChild("InsideButton")
local UIButton = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ExitCode"):WaitForChild("TextButton")
local camera
local oldCF
local TS = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local closePos = {51.526, 4.847, 18.676}
local openPos = {51.526, 11.959, 18.676}
local code = 9124
ProximityPrompt.Triggered:Connect(function()
if db then return end
db = true
UIButton.Visible = true
ProximityPrompt.Enabled = false
camera = game.Workspace.CurrentCamera
oldCF = camera.CFrame
camera.CameraType = Enum.CameraType.Scriptable
local tween = TS:Create(camera, info, {CFrame = cameraPart.CFrame})
tween:Play()
task.wait(1)
db = false
end)
UIButton.MouseButton1Click:Connect(function()
if db then return end
db = true
screen.Text = ""
camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local tween = TS:Create(camera, info, {CFrame = oldCF})
UIButton.Visible = false
ProximityPrompt.Enabled = true
tween:Play()
task.wait(1)
camera.CameraType = Enum.CameraType.Custom
task.wait(1)
db = false
end)
for i, v in pairs(referance.Parent.Buttons:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function()
if doorStatus == "Closed" and db == false and #screen.Text < 4 then
screen.Text = screen.Text .. v.Name
end
end)
end
function flashWrongCode()
screen.TextColor3 = Color3.new(1, 0, 0.0156863)
for i = 1, 5 do
screen.TextTransparency = 0
task.wait(0.2)
screen.TextTransparency = 1
task.wait(0.2)
end
screen.TextTransparency = 0
screen.TextColor3 = Color3.new(1, 1, 1)
screen.Text = ""
end
confirm.ClickDetector.MouseClick:Connect(function()
if db or doorStatus == "Open" then return end
db = true
if tonumber(screen.Text) == code then
doorStatus = "Open"
screen.TextColor3 = Color3.new(0, 1, 0.0156863)
UIButton.Visible = false
game.SoundService["Game Sound Correct"]:Play()
for i = 1,100 do
main.Position += Vector3.new(0, 0.07112, 0)
task.wait(0.001)
end
camera = game.Workspace.CurrentCamera
local tween = TS:Create(camera, info, {CFrame = oldCF})
tween:Play()
task.wait(1)
screen.TextColor3 = Color3.new(1, 1, 1)
screen.Text = ""
camera.CameraType = Enum.CameraType.Custom
ProximityPrompt.Enabled = true
db = false
else
-- screen.Text = ""
game.SoundService["Menu Error"]:Play()
flashWrongCode()
task.wait(1)
db = false
end
end)
insideButton.ClickDetector.MouseClick:Connect(function()
if db then return end
if doorStatus == "Open" then
db = true
doorStatus = "Closed"
insideButton.BrickColor = BrickColor.new("Sea green")
for i = 1,100 do
main.Position -= Vector3.new(0, 0.07112, 0)
task.wait(0.001)
end
task.wait(1)
db = false
else
db = true
doorStatus = "Open"
insideButton.BrickColor = BrickColor.new("Really red")
for i = 1,100 do
main.Position += Vector3.new(0, 0.07112, 0)
task.wait(0.001)
end
task.wait(1)
db = false
end
end)