MouseButton1Down activates multiple times, despite an if statement,

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want a button that when pressed gives the player a boost of speed for a short period of time, with the player being able to reset the timer every click, The button is supposed to be annoying and inconvenient.

The way I have it set up, is through two timers
One that manages how long the sprint lasts “SprintTimer”
And a delay “Subtract Timer” between subtracting 1 from the “SprintTimer”

  1. What is the issue? Include screenshots / videos if possible!

However, despite my best efforts, it keeps subtracting from SprintTimer if the player spam clicks the button, until it goes into the negatives and the player needs to wait to use the button again, before they can sprint. This is not intentional nor what I want.

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I have tried an if statement, putting it into another script, IntValues, changing values
Unfortunately none of these have worked.

Scripts



Explorer

Output log (Script intended effect)

Output Log (Script unintended Side-Effect)

Video of the error

I’m not 100% sure I understand, but:

Try moving line 16 of SprintHandler to be within the MouseButton1Down function.
(also, you may want to use .Activated instead of .MouseButton1Down (although it depends on your use case)

1 Like

Cant you simply add an if check to see if the value of SprintTimer will become negative after subtracting 1. If yes, simply set to 0?

1 Like

Thank you this worked perfectly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.