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

Nothing will print in "Mouse.KeyDown:Connect" script?

Asked by 6 years ago

Hey, I'm testing a script, but when I press Z nothing is printed. I'm trying to add a delay when I press Z, but nothing will print... Please help

01local repstore = game:WaitForChild("ReplicatedStorage")
02local Remote = repstore:WaitForChild("IceStart")
03 
04 
05Player = game.Players.LocalPlayer
06Mouse = Player:GetMouse()
07 
08cool = true
09 
10Mouse.KeyDown:Connect(function(key)
11key = key:lower()
12if key == "z" then
13 if cool == true then return end
14 cool = false
15 
View all 21 lines...
0
Use local variables, key down is deprecated use userinputservice DinozCreates 1070 — 6y

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago

Try to use UserInputService the Mouse.KeyDown is deprecated

You can see more here: UserInputService - Wiki

Remember, UserInputService can used in LocalScript or ModuleScript. not work in Server Script

here is a example:

01local service = game:GetService("UserInputService")
02 
03service.InputBegan:Connect(function(input,gameproc)
04    if not gameproc then -- (gameProcessed)
05        if input.KeyCode == Enum.KeyCode.F then
06            print("You pressed F")
07        end
08    end
09end)
10 
11service.InputBegan:Connect(function(input,gameproc)
12    if not gameproc then -- (gameProcessed)
13        if input.KeyCode == Enum.KeyCode.F then
14            wait(0.07)
15            print("You stoped with pressing F")
16        end
17    end
18end)

You can try this:

01local service = game:GetService("UserInputService")
02 
03local debounce = true
04 
05service.InputBegan:Connect(function(input,gameproc)
06    if not gameproc and debounce == true then -- (gameproc = gameProcessed)
07        if input.KeyCode == Enum.KeyCode.Z then
08            debounce = false
09            print("Working")
10            wait(5)
11            debounce = true
12        end
13    end
14end)

Hope it helped :)

Ad
Log in to vote
3
Answered by 6 years ago

Use UserInputService

Like that

01local UserInputService = game:GetService('UserInputService')
02 
03local debounce = true
04 
05UserInputService.InputBegan:Connect(function(input)
06    if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Z and debounce then
07        debounce = false
08        print("Working")
09        wait(5)
10        debounce = true
11    end
12end)

Answer this question