Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

KeyDown not working?

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

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

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

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

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

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.

3 comments

0

I meant the up arrow.

0

Well, I don't know about the up arrow part. Maybe put "Up"?

0

I did J, but it's still not working, I saw this in a weapon and it worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.