:Emit(rate) increases the rate every time its called

Hello.

I’m using FireServer to let the server handle particle emitting. This is done through a LocalScript.
Every time you do the move in the GIF below, it will emit >10< particles on two emitters, and enable them as well.

What it's supposed to look like

Image from Gyazo

However, the more I do this, for some reason the emit rate keeps increasing.

What it looks like after a while

Image from Gyazo

Code that responds to FireServer and emits the particles

image

Does anyone know why it seems to be stacking the emit rate?

The code you’ve provided is not enough to fully diagnose the issue. The most likely situation is that either the function that emits the particles duplicates or the localscript itself duplicates. Here are some questions that may help:

  • Where is the localscript stored? Is it cloned and added to the player when the effect is meant to run, or is it always in the player?
  • Does the rate appear to increase after every use, or only when the player respawns?
1 Like

It’s inside a Tool, in the player’s Backpack.
FireServer is fired on a KeyframeReached event:

Code

Yes, the rate increases every time I execute the move.
This will return to normal once the player respawns.

Interesting. Here’s an additional question:

  • The code you posted is tabbed to the right. Is it nested inside a Tool Equipped or a Tool Activated event? If not, what is it nested inside of?
1 Like

It responds to an input, “F” to be exact. I’m using UserInputService for this:

Code

image

It’s very unlikely that spamming the key is the cause of this (because it literally wont let me). It just stacks up the emit rate every time I activate the move, no matter how much time there is between moves.

So if I’m understanding this right, the entire function runs inside of an event like UserInputService.InputBegan?

1 Like

Yes. I have it return on several occasions as well:

Code

image

active returns true if the player has actually selected the tool.

Got it.

The issue is that a connected event stays connected until forcefully disconnected. In your case, this only happens when the player respawns.

Every single time you use the tool, you are connecting to KeyframeReached. This means that on the first use, it fires once, but on the second use, it fires twice, and so on.

To fix this, you should take the KeyframeReached event and put it outside of the UserInputService event. Assuming that “fireF” isn’t created dynamically within the UserInputService event, you should only need to declare the KeyframeReached event once. :slight_smile:

3 Likes

Amazing, thank you!
I did not know this up till now.

1 Like