|
| 08 Aug 2017 12:24 AM |
Hello! I was wondering what the best possible way to prevent the Mouse.KeyDown event from firing more than once, considering debounce isn't working.
I bring this up because I am at a crossroads. Currently, the weapon I have right now allows the player to continue running even if the weapon isn't equipped. However, when the player presses a key and calls the KeyDown event, the event fires more than once, depending on how many times the weapon has been equipped.
It is imperative that the running is disabled when the player hits the "f" key (run key) if it is still active, but I can't figure out a way from stopping the event from triggering more than once. I tried to put it outside the .Equipped event of the tool, but to no avail, and putting in a debounce, which the same result.
Any help on this is appreciated! Thanks! ^^
Sometimes, it's the people no one imagines anything of, who do the things that no one can imagine. |
|
|
| Report Abuse |
|
|
sglrty
|
  |
| Joined: 03 Jan 2017 |
| Total Posts: 336 |
|
| |
|
|
| 08 Aug 2017 12:29 AM |
Literally this:
local Mouse = game.Players.LocalPlayer:GetMouse()
Tool.Equipped:Connect(function() wait() Mouse.KeyDown:Connect(function(Key) print(Key) -- A whole bunch of other irrelevant code, this just fires twice and I can't figure out why. end) end)
Sometimes, it's the people no one imagines anything of, who do the things that no one can imagine. |
|
|
| Report Abuse |
|
|
sglrty
|
  |
| Joined: 03 Jan 2017 |
| Total Posts: 336 |
|
|
| 08 Aug 2017 12:37 AM |
| The event's not firing more than once in my Studio.. |
|
|
| Report Abuse |
|
|
Exzeption
|
  |
| Joined: 01 Nov 2011 |
| Total Posts: 1312 |
|
|
| 08 Aug 2017 12:41 AM |
get the Mouse.KeyDown function out of the tool.Equipped function and when tool is equipped set a value (say, "equipped") to true and when Mouse.KeyDown is fired check if equipped is true
be sure to add a tool.Unequipped and set equipped to false too |
|
|
| Report Abuse |
|
|
Wrathsong
|
  |
| Joined: 05 Jul 2012 |
| Total Posts: 22393 |
|
|
| 08 Aug 2017 12:44 AM |
I wouldn't nest the connection for the keydown event inside the equipped event, if you want the thing to only fire when equipped you can just make a check. And I'd also use UserInputService, but here you go
local con con = Mouse.Keydown:Connect(function(Key) con:Disconnect() print(Key) end)
UIS tutorial if you're interested
https://www.youtube.com/watch?v=NWx5XQbpHBU
|
|
|
| Report Abuse |
|
|