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

Why is this KeyDown function not working?

Why isn't this script working? Everything seems correct. This is a local script in startergui.

local debounce = false
local plyr = game.Players.LocalPlayer
local mouse = plyr:GetMouse()

mouse.KeyDown:connect(function(key)
			if not debounce then
				debounce = true
				if string.lower(key) == "r" then
			plyr:LoadCharacter()
			wait(3)
			debounce = false
				elseif key:byte() == 63 then
					game.Lighting.HELP:Clone().Parent = plyr.PlayerGui
					wait(3)
					debounce = false
		end
	end
end)

2 comments

0

Are you getting any Output?

0

Nope.

2 answers

✓ Accepted answer

( Note : <http://wiki.roblox.com/index.php?title=Taking_keyboard_input >)

local debounce = false
local plyr = game.Players.LocalPlayer
local mouse = plyr:GetMouse()

mouse.KeyDown:connect(function(key)
            if debounce == false and key == 'r' then -- Works just fine
                debounce = true
            		plyr:LoadCharacter()
           			 delay(3,function()
					debounce = false
				end)
                elseif key == 'q' and debounce==false then  -- There is no 63 byte
              game.Lighting.HELP:Clone().Parent = plyr.PlayerGui
            delay(3,function()
				debounce = true
		end)
    end
end)

1 comment

0

Good luck! :D

Try using this code as the first line.

wait(.5)

This usually fixes things for local scripts not always working. Due to local scripts loading faster than some player aspects this usually helps with letting them load first. If this doesn't work try adding a:

print(key)

, inside of the mouse.KeyDown:connect(function(key), as the next line in it. Here is the code that I think may work.

wait(.5)

local debounce = false
local plyr = game.Players.LocalPlayer
local mouse = plyr:GetMouse()
 
mouse.KeyDown:connect(function(key)
	    print(key)
            if not debounce then
                debounce = true
                if string.lower(key) == "r" then
            plyr:LoadCharacter()
            wait(3)
            debounce = false
                elseif key:byte() == 63 then
                    game.Lighting.HELP:Clone().Parent = plyr.PlayerGui
                    wait(3)
                    debounce = false
        end
    end
end)

1 comment

0

Doesn't work.

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