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 10 years ago

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

01local debounce = false
02local plyr = game.Players.LocalPlayer
03local mouse = plyr:GetMouse()
04 
05mouse.KeyDown:connect(function(key)
06            if not debounce then
07                debounce = true
08                if string.lower(key) == "r" then
09            plyr:LoadCharacter()
10            wait(3)
11            debounce = false
12                elseif key:byte() == 63 then
13                    game.Lighting.HELP:Clone().Parent = plyr.PlayerGui
14                    wait(3)
15                    debounce = false
16        end
17    end
18end)
0
Are you getting any Output? adark 5487 — 10y
0
Nope. EzraNehemiah_TF2 3552 — 10y

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 10 years ago

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

01local debounce = false
02local plyr = game.Players.LocalPlayer
03local mouse = plyr:GetMouse()
04 
05mouse.KeyDown:connect(function(key)
06            if debounce == false and key == 'r' then -- Works just fine
07                debounce = true
08                    plyr:LoadCharacter()
09                     delay(3,function()
10                    debounce = false
11                end)
12                elseif key == 'q' and debounce==false then  -- There is no 63 byte
13              game.Lighting.HELP:Clone().Parent = plyr.PlayerGui
14            delay(3,function()
15                debounce = true
16        end)
17    end
18end)
0
Good luck! :D MessorAdmin 598 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

Try using this code as the first line.

1wait(.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:

1print(key)

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

01wait(.5)
02 
03local debounce = false
04local plyr = game.Players.LocalPlayer
05local mouse = plyr:GetMouse()
06 
07mouse.KeyDown:connect(function(key)
08        print(key)
09            if not debounce then
10                debounce = true
11                if string.lower(key) == "r" then
12            plyr:LoadCharacter()
13            wait(3)
14            debounce = false
15                elseif key:byte() == 63 then
View all 21 lines...
0
Doesn't work. EzraNehemiah_TF2 3552 — 10y