Help with random code/Safe script

HI! Ewof here, and I have a problem. You see, when I try to enter a code, it doesn’t work, even if it is the correct code.

Here’s the script:

local Code = math.random(1000, 9999)
local Input = script.Parent.Code
local InputPlane = script.Parent.Safe.Input.SurfaceGui.Frame.TextLabel
local Paper = script.Parent.Paper.SurfaceGui.Frame.Code
local clear = script.Parent.Safe.Clear.ProximityPrompt
local enter = script.Parent.Safe.Enter.ProximityPrompt

Paper.Text = Code

function Clear()
	Input.Value = ""
	InputPlane.Text = Input.Value
end

clear.Triggered:connect(Clear)

function Enter()

	if Input.Value == Code then
		InputPlane.TextColor3 = Color3.new(0, 1, 0)
		InputPlane.Text = "CORRECT"
	else
		InputPlane.Text = "INCORRECT"
		InputPlane.TextColor3 = Color3.new(1, 0, 0)
		wait(3)
		InputPlane.Text = "TRY AGAIN"
		InputPlane.TextColor3 = Color3.new(1, 1, 1)
	end
end

enter.Triggered:connect(Enter)

Here’s a video:

More things:

  • The typing of the input and the input box itself (safe) are connected by this code
local screenGui = script.Parent -- the code is in a local script.

local InputBox = screenGui.Frame.TextboxHolder.TextBox
local OutputBox = game.Workspace.SafeSystem.Safe.Input.SurfaceGui.Frame.TextLabel

InputBox.FocusLost:Connect(function(PressedEnter)
	if PressedEnter then
		OutputBox.Text = InputBox.Text
	end
end)
  • The value that I use is a StringValue
  • The text works fine, but the entering of code doesn’t

If anyone can help, I would highly appreciate it, ty!

2 Likes

For this line you are comparing a string and a number. Try doing:

if tonumber(Input.Value) == Code then
2 Likes

I think u forgot to change the value? After focuslost also u cant change the value with localscript bc it dont affect with script

1 Like

Fixed it, but now everytime I just press the Enter button, it says Correct, even though its the wrong code/empty. Can somebody help me?

local Code = math.random(1000, 9999)
local Input = script.Parent.Code
local InputPlane = script.Parent.Safe.Input.SurfaceGui.Frame.TextLabel
local Paper = script.Parent.Paper.SurfaceGui.Frame.Code
local clear = script.Parent.Safe.Clear.ProximityPrompt
local enter = script.Parent.Safe.Enter.ProximityPrompt
local input = script.Parent.Safe.Inputs.ProximityPrompt
local door = script.Parent.Safe.Door.Door.PromptObject

Paper.Text = Code

function Clear()
	InputPlane.Text = ""
	Input.Value = InputPlane.Text
end

clear.Triggered:connect(Clear)

function Enter()
	if Input.Value or InputPlane.Text == Code then
		InputPlane.TextColor3 = Color3.new(0, 1, 0)
		InputPlane.Text = "CORRECT"
		wait(2)
		InputPlane.Text = "OPENING..."
		InputPlane.TextColor3 = Color3.new(1, 1, 1)
	else
		InputPlane.Text = "INCORRECT"
		InputPlane.TextColor3 = Color3.new(1, 0, 0)
		wait(3)
		InputPlane.Text = "TRY AGAIN"
		InputPlane.TextColor3 = Color3.new(1, 1, 1)
	end
end

enter.Triggered:connect(Enter)

Note:

  • Changed the NumberValue to a StringValue
1 Like