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

KeyDown not working?

Asked by 10 years ago

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?

function onkeyDown(key) 
    if key == 38 then
        script.Parent.Position.Z = 200
    end
end

or

function onkeyDown(key) 
    if key == 38 then
        script.Parent.Position = {0.5, -50},{0, 200}
    end
end

Thanks!

5 answers

Log in to vote
3
Answered by
Aethex 256 Moderation Voter
10 years ago

You need to use string.byte to use the number of the key.

function onkeyDown(key) 

    if key:byte() == 38 then

        script.Parent.Position = UDim2.new(0.5, -50, 0, 200);

    end

end

Ad
Log in to vote
0
Answered by
Versimn 20
10 years ago
function onkeyDown(key)
    if tonumber(string.byte(key)) == 38 then
        script.Parent.Position = UDim2.new(.5,-50,0,200)
    end
end
PATHHERE.MouseButton1Click:connect(onkeyDown) --PATHHERE = path to the gui button

should work, idk if tonumber is required :P

Log in to vote
-1
Answered by
IcyEvil 260 Moderation Voter
10 years ago

from what I see in the comments you need to do this

function onkeyDown(key) 

    if key:byte() == "38" then

        script.Parent.Position = UDim2.new(0.5, -50, 0, 200);

    end

end

Log in to vote
-2
Answered by 10 years ago

if the key part works then this will

function onkeyDown(key) 
    if key == 38 then
        script.Parent.Position = UDim2.new(.5,-50,0,200)
    end
end

Log in to vote
-3
Answered by 10 years ago

Few mistakes. One:

function onkeyDown(key)
    if key ==  "38" then -- Quotation Marks
        script.Parent.Position = {0.5, -50},{0, 200}
    end
end

For two: you might want to pick another letter instead of "^" because you have to hold shift.

function onkeyDown(key)
    if key ==  "Letter goes here" then -- Quotation Marks and any letter you want.
        script.Parent.Position = {0.5, -50},{0, 200}
    end
end

Though, I'm not highly 100% sure it will work.

0
I meant the up arrow. Grenaderade 525 — 10y
0
Well, I don't know about the up arrow part. Maybe put "Up"? DesignerDavid 0 — 10y
0
I did J, but it's still not working, I saw this in a weapon and it worked. Grenaderade 525 — 10y

Answer this question