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

How would I Fix this KeyDown Event?

Asked by
woodengop 1134 Moderation Voter
9 years ago

What is wrong with this Script. Is it because I'm using the GetMouse event or is it because of line 6?

open = script,Parent

function KeyDown(key)
    local key = key:lowerkey()
    if key == "e"  then
        game.StarterGui.sttngpg.plrstats.Visible = true
    end
end

open.Parent.plrstats:GetMouse().KeyDown:connect(KeyDown)

please Help!

0
It's because of line 6; You are changing the GUI from 'StarterGui', not the actual Player's 'PlayerGui', also, 'lowerkey' is not an actual Method, consider changing to 'key:lower()'? TheeDeathCaster 2368 — 9y
0
How would I write that? woodengop 1134 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

Your problems are lines 4, and 6: On line 4, lowerkey is not a valid Method, consider changing to key:lower()?, and, on line 6, you are only changing the StarterGui's GUI version, lastly, there is another two problems I am noticing; Lines 6 and the last Line; You do not need to use that much code, the more problems with two codes are; What if they do not exist? Then what? What can I do to prevent this?, this can also be fixed, however, it will require using the WaitForChild Method. Now that I have pointed out all these problems, lets fix your code;

local open = script.Parent
local plrstats = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("plrstats") --This looks much cleaner, doesn't it? ;)
local plrstats2= game.Players.LocalPlayer:GetMouse() --This looks much cleaner, doesn't it? ;)


function KeyDown(key)
    local key = key:lower()
    if key == "e"  then
        plrstats.Visible = true
    end
end

plrstats2.KeyDown:connect(KeyDown)

Ah, now doesn't your code looks allot better, and cleaner? :) Hope this helped!

0
doesn't work. Have you tested it? woodengop 1134 — 9y
0
Are you using a 'Server-Sided' script [Normal Script], or a 'Client-Sided' script [Local Script]? TheeDeathCaster 2368 — 9y
0
Client-Sided woodengop 1134 — 9y
0
Huh, then, I must not know how the code is set up. Is your issue that 'KeyDown' does not work? TheeDeathCaster 2368 — 9y
View all comments (6 more)
0
yes woodengop 1134 — 9y
0
Hmm, it may either that 'plrstats' is not the actual name, or.. Wait.. I think I might know the issue! Is 'plrstats' a 'ScreenGui' or 'TextLabel' type instance? TheeDeathCaster 2368 — 9y
0
Its a Frame woodengop 1134 — 9y
0
That's your problem; Your not using a 'ScreenGui' type instance, that is REQUIRED for GUIs to show up. Simply create a new 'ScreenGui', then put your Frame in it. Fixed. TheeDeathCaster 2368 — 9y
0
Thanks man! Your the best! woodengop 1134 — 9y
0
No problem! :D Glad to help! :) TheeDeathCaster 2368 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

First: It's not:

local key = key:lowerkey()

Change it for:

local key = key:lower()

And continue making the script <3

0
doesn't work woodengop 1134 — 9y
0
Remember change line 6: Change StarterGui for PlayerGui. jeffreyubi 0 — 9y

Answer this question