An simple fix is you add a Button called Submit or Enter so that every time it is clicked, it checks the text and if the text is correct then it gives the player whatever the code gives, for example;
This is the positions;
--------------StarterGui
-----------ScreenGui
---------TextBox
---------SubmitButton(TextButton)
-------LocalScript
This means StarterGui is the main parent, then screen Gui and inside of ScreenGui you have a TextBox and a button and inside of button you have the local script which is the controller,
Now code;
01 | local Plr = game.Players.LocalPlayer |
02 | local shop = script.Parent.Parent.Parent:WaitForChild( 'ShopGUI' ).ShopMaster |
03 | local SB = script.Parent |
04 | local CB = SB.Parent:WaitForChild( 'TextBox' ) |
06 | local CodeKnife = game.ReplicatedStorage.Knives:WaitForChild( 'CodeKnife' ) |
08 | SB.MouseButton 1 Down:Connect( function () |
09 | if CB.Text = = Code then |
11 | CodeKnife.Parent = Plr.Backpack |
Make sure you have all Gui Objects and change what is necessary. If you followed along and did everything then it should work, if it doesn't work comment the error or fix it if you can.
:WaitForChild()
waits for the child to load in so that it would work in both studio and game.
If this helped then please accept answer ;)
Good luck and have fun developing!