So, I'm trying to make a Gui Game, but the "onkeydown" isn't working, 38 means ^. Thats the key number. But it's not working, any help?
1 | function onkeyDown(key) |
2 | if key = = 38 then |
3 | script.Parent.Position.Z = 200 |
4 | end |
5 | end |
or
1 | function onkeyDown(key) |
2 | if key = = 38 then |
3 | script.Parent.Position = { 0.5 , - 50 } , { 0 , 200 } |
4 | end |
5 | end |
Thanks!
You need to use string.byte to use the number of the key.
1 | function onkeyDown(key) |
2 |
3 | if key:byte() = = 38 then |
4 |
5 | script.Parent.Position = UDim 2. new( 0.5 , - 50 , 0 , 200 ); |
6 |
7 | end |
8 |
9 | end |
1 | function onkeyDown(key) |
2 | if tonumber (string.byte(key)) = = 38 then |
3 | script.Parent.Position = UDim 2. new(. 5 ,- 50 , 0 , 200 ) |
4 | end |
5 | end |
6 | PATHHERE.MouseButton 1 Click:connect(onkeyDown) --PATHHERE = path to the gui button |
should work, idk if tonumber is required :P
from what I see in the comments you need to do this
1 | function onkeyDown(key) |
2 |
3 | if key:byte() = = "38" then |
4 |
5 | script.Parent.Position = UDim 2. new( 0.5 , - 50 , 0 , 200 ); |
6 |
7 | end |
8 |
9 | end |
if the key part works then this will
1 | function onkeyDown(key) |
2 | if key = = 38 then |
3 | script.Parent.Position = UDim 2. new(. 5 ,- 50 , 0 , 200 ) |
4 | end |
5 | end |
Few mistakes. One:
1 | function onkeyDown(key) |
2 | if key = = "38" then -- Quotation Marks |
3 | script.Parent.Position = { 0.5 , - 50 } , { 0 , 200 } |
4 | end |
5 | end |
For two: you might want to pick another letter instead of "^" because you have to hold shift.
1 | function onkeyDown(key) |
2 | if key = = "Letter goes here" then -- Quotation Marks and any letter you want. |
3 | script.Parent.Position = { 0.5 , - 50 } , { 0 , 200 } |
4 | end |
5 | end |
Though, I'm not highly 100% sure it will work.