generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Preventing multiple callings on event | Debounce not working

Previous Thread :: Next Thread 
Julian_Orteil is not online. Julian_Orteil
Joined: 14 Aug 2012
Total Posts: 968
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 is not online. sglrty
Joined: 03 Jan 2017
Total Posts: 336
08 Aug 2017 12:27 AM
paste code?
Report Abuse
Julian_Orteil is not online. Julian_Orteil
Joined: 14 Aug 2012
Total Posts: 968
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 is not online. 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 is not online. 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 is online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image