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

Why is this KeyDown function not working? [closed]

Asked by 9 years ago

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)
0
Are you getting any Output? adark 5487 — 9y
0
Nope. EzraNehemiah_TF2 3552 — 9y

Locked by EzraNehemiah_TF2, Redbullusa, and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 9 years ago

( 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)
0
Good luck! :D MessorAdmin 598 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

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)
0
Doesn't work. EzraNehemiah_TF2 3552 — 9y