It is supposed to tween a GUI onscreen when you press 'h'
01 | g = script.Parent |
02 | f = g.Frame |
03 |
04 | p = game.Players.LocalPlayer |
05 | m = p.GetMouse() |
06 |
07 | function help() |
08 | m.KeyDown:connect( function (key) |
09 | if Key:byte() = = 104 then |
10 | f:TweenPosition(UDim 2. new( 0 , 100 , 0 , 250 )) |
11 | end |
12 | end ) |
13 | end |
14 |
15 | coroutine.resume(couroutine.create(help)) |
On line 9, Key
is nil, while key
is not.
Change Line 9 to: if key == "h" then
. I personally prefer to use characters themselves in those cases, as it is more readable.
There are a few problems here.
1 | p = game.Players.LocalPlayer |
2 | m = p.GetMouse() |
GetMouse
is a Method, therefore it needs to be called with a :
1 | m.KeyDown:connect( function (key) |
2 | if Key:byte() = = 104 then |
You define the variable as key
but then used it as Key
. Just change one or the other to match.
You also are randomly calling this as a coroutine? Why is that?
To add to Jobro's answer, there's no reason to set up your event inside of a function running in another thread. Events will run asynchronously. Also, remember that you can only use GetMouse
in a LocalScript.
In your code, the argument given to the function is stored in key
. However, you use the variable Key
in your if statement. Also, instead of converting key
to a number, you can simply check if that variable key
is equal to the string "h"
.