Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PassCode Gui does not work?

Hi there, I was making a Passcode GUI in my place and it seems that it does not work. The problem is that, It won't tell whether the Passcode is right or wrong and if the Passcode is correct, It won't remove the GUI. This script is placed in the StarterPack inside no Model or Part.

code = "EnterCodeHere"
Player = script.Parent.Parent.PlayerGui
Mouse = Player:GetMouse()
codegui = Player.PassCodeGUI
codeteller = codegui.PassCode.PassCodeTeller
codetype = codegui.PassCodeHere

function onKeyDown()
local key = key.lower()
    if key:byte() == 13 then -- From this part it stops working.
        if (codetype.Text == code) then 
            codeteller.Text = "Correct"
            wait(2)
            script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
            codegui:remove()
        else
            codeteller.Text = "Wrong"
            wait(3)
            codeteller.Text = "Enter Passcode"
        end
    end
end
Mouse.KeyDown:connect(onKeyDown) 

This Script is a LocalScript. There are 3 frames. One is BackGround, Credits and PassCode. There is a NormalScript which makes the GUI visible.

2 comments

1

LocalScripts can't run inside Workspace... you need to put it in StarterGui or StarterPack..

0

Wait. Sorry I forgot that I placed the script in StarterPack. Sorry about that.

2 answers

✓ Accepted answer

I'm going to suggest a couple things to you.

1) - Make sure that you're typing in the exact code that the variable 'code' is holding, EnterCodeHere.

2) - Make sure this is a localscript, directly inside of a TextBox.

3) - Check your parenting after doing suggestion 2

4) - Use the FocusLost function to determine when the player pressed enter, rather than KeyDown events.

5) - Use the Destroy function, not the Remove function.

local code = "EnterCodeHere"
local Player = game.Players.LocalPlayer
local gui = script.Parent

gui.FocusLost:connect(function(enter)
	if enter then --Check if the focus was lost by the client pressing enter
		if gui.Text == code then
			gui.Text = 'Correct'
			--*Destroy* the gui here
			Player.Character.Humanoid.WalkSpeed = 16
		else
			gui.Text = 'Wrong'
			wait(3)
			gui.Text = 'Enter Passcode'
		end
	end
end)

I'm sorry that I can't aid you more accurately due to me not knowing your full hierarchy for the gui.

First off localscripts will not work unless they are in the Player by one of three ways:

  1. In the player's backpack
  2. In the player's character
  3. In the player's PlayerGui.

Now how are you accessing the player's PlayerGui in line 2 if the script is in Workspace? Also you cant use :GetMouse() on the player's PlayerGui, you have to use it on the parent. Mouse = Player.Parent:GetMouse()

2 comments

0

I said It is in StarterPack...

0

Sorry I didnt see when I was typing

This discussion is preserved as it was. New answers, comments, and votes are closed.