Weird code entry bug

I’m making a code entry system in the form of a gui for my puzzle/story game, and I’m running in to an interesting bug.

For whatever reason, the script only says the code is correct on the second time you enter it.

I can’t find any glaring mistake, and the code is relatively simple so it should be working.

local RE = game.ReplicatedStorage.remoteEvents["Story I"]["Level 1"].electrical
local closeButton = script.Parent.close
local confirmButton = script.Parent.confirm
local codeEntry = script.Parent.codeEntry
local Frame = script.Parent
local player = game.Players.LocalPlayer
local TS = game:GetService("TweenService")



function open()
	local bTween = TS:Create(game.Lighting.Blur, TweenInfo.new(.3), {Size = 20}):Play()
	Frame.Visible = true
end



RE.OnClientEvent:Connect(function(input)
	if input == "open" then
		open()
		
		
		
	end
end)



closeButton.MouseButton1Click:Connect(function()
	Frame.Visible = false
	local bTween = TS:Create(game.Lighting.Blur, TweenInfo.new(.3), {Size = 0}):Play()
	RE:FireServer("closed")
end)

confirmButton.MouseButton1Click:Connect(function()
-- this is where I believe the issue would be...
	if codeEntry.Text == workspace["Story I"]["Level 1"].answerButton.code.Value then
		Frame.Visible = false
		TS:Create(game.Lighting.Blur, TweenInfo.new(.3), {Size = 0}):Play()
		RE:FireServer("foundCode")
	else
		codeEntry.Text = "Incorrect"
		wait(.7)
		codeEntry.Text = ""
	end
end)

Here is a video of what I mean. Note, the demo code is “123”.
(it’s an unlisted YT vid)

Any help is greatly appreciated!

You could try setting TextBox.Text = "" when UI is opened. If it will work, check if textbox.text has accidentally and spaces or any other invisible characters.

Also if my eyes dont lie, when you opened UI, the placeholder text was invisible and appeared only after it said “Incorrect”. You probably unintentially left space in textbox.text.

1 Like

what do you mean when UI is opened?

definitionally, the player sets the text of TextBox by entering the code, so I’m not sure I understand what you’re saying.

When player presses the button (red one). I just updated the previous post with possible fix

Thank you so much I just realized my mistake… :sweat_smile:

Have a nice rest of your day!

1 Like

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