Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

PassCode Gui does not work? [closed]

Asked by 9 years ago

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.

1
LocalScripts can't run inside Workspace... you need to put it in StarterGui or StarterPack.. NinjoOnline 1146 — 9y
0
Wait. Sorry I forgot that I placed the script in StarterPack. Sorry about that. PlayingOBC 70 — 9y

Locked by NinjoOnline, Goulstem, and woodengop

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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.

Ad
Log in to vote
0
Answered by
parkderp1 105
9 years ago

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()

0
I said It is in StarterPack... PlayingOBC 70 — 9y
0
Sorry I didnt see when I was typing parkderp1 105 — 9y