Emit() particles keep piling up if I move

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

  1. What do you want to achieve?
  • Holding M will genereate particles until let go
  1. What is the issue? Include screenshots / videos if possible!
  • Particles keep piling up if I move and the script breaks

1

  • How it’s intended to work

2

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • Removing the Clone particle out of the function, adding a particle.enable

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!

particula:Clone()
particula.Parent = hrp
particula.Enabled = false

UserInputService.InputBegan:Connect(function(Input, gameProcessed) 
	while UserInputService:IsKeyDown(Enum.KeyCode.M) do
		local dt = wait(REGEN_STEP)
		local dh = dt*REGEN_RATE*Humanoid.MaxHealth
		print("M held")
		particula:Emit()
		Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
		wait(1)
		particula:Clear()
		particula.Enabled = false
		
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Set the wait time to ParticleEmitters Life Time

wait(particula.Lifetime.Max)

It still does it, just takes a bit longer to do it

I think I see your issue, whenever a new Input begins it will bug out and will try to end the loop, so add an if statement to check if the input is really M

UserInputService.InputBegan:Connect(function(Input, gameProcessed) 
	if Input.KeyCode == Enum.KeyCode.M then
		while UserInputService:IsKeyDown(Enum.KeyCode.M) do
			local dt = wait(REGEN_STEP)
			local dh = dt*REGEN_RATE*Humanoid.MaxHealth
			print("M held")
			particula:Emit()
			Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
			wait(1)
			particula:Clear()
			particula.Enabled = false	
		end
	end
end)

Yeah! That fixed it thank you!

You should also use return so that you don’t fall into an endless indentation loop.

if Input.KeyCode ~= Enum.KeyCode.M then return end

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