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
01 | local repstore = game:WaitForChild( "ReplicatedStorage" ) |
02 | local Remote = repstore:WaitForChild( "IceStart" ) |
03 |
04 |
05 | Player = game.Players.LocalPlayer |
06 | Mouse = Player:GetMouse() |
07 |
08 | cool = true |
09 |
10 | Mouse.KeyDown:Connect( function (key) |
11 | key = key:lower() |
12 | if key = = "z" then |
13 | if cool = = true then return end |
14 | cool = false |
15 |
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:
01 | local service = game:GetService( "UserInputService" ) |
02 |
03 | service.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 |
09 | end ) |
10 |
11 | service.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 |
18 | end ) |
You can try this:
01 | local service = game:GetService( "UserInputService" ) |
02 |
03 | local debounce = true |
04 |
05 | service.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 |
14 | end ) |
Hope it helped :)
Use UserInputService
Like that
01 | local UserInputService = game:GetService( 'UserInputService' ) |
02 |
03 | local debounce = true |
04 |
05 | UserInputService.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 |
12 | end ) |