Explosion effect won't expand properly when activated simultaneously

Hello, my script detects whenever an object touches a beam fired by the player, if the beam hits a character then the it would have a explosion effect. The effect works perfectly fine when it hits one target, but when it hits multiple targets simultaneously it bugs out.
Heres what it looks like

The desired effect is what happened to the first zombie

heres the script


Targets = {}
debris = game:GetService("Debris")
effect = game.ReplicatedStorage.TOOLS.EFFECTS.BeamEffects:Clone()
db = true

script.Parent.Touched:Connect(function(hit)
	humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and hit.Parent.Name ~= _G.BEAMNAM then
	Character = hit.Parent
	if Targets[Character] == nil or tick() - Targets[Character] > 5 then
		print("f")
		Targets[Character] = tick()
		humanoid.Health = humanoid.Health - 10
		humanoid.WalkSpeed = 5
		
	
		effect1 = effect:Clone()
		effect2 = effect:Clone()
		effect3 = effect:Clone()
		effect4 = effect:Clone()
		effect5 = effect:Clone()
	
		for i = 1,10 do 
		
		effect.Parent = game.Workspace
		effect.CFrame = humanoid.Parent.Torso.CFrame * CFrame.new(.3,.4,.6)
				effect1.Parent = game.Workspace
		effect1.CFrame = humanoid.Parent.Head.CFrame * CFrame.new(.2,.2,.2)
				effect2.Parent = game.Workspace
		effect2.CFrame = humanoid.Parent["Right Arm"].CFrame * CFrame.new(-.2,-.2,-.2)
				effect3.Parent = game.Workspace
		effect3.CFrame = humanoid.Parent["Left Arm"].CFrame * CFrame.new(.3,.6,.4)
				effect4.Parent = game.Workspace
		effect4.CFrame = humanoid.Parent["Left Leg"].CFrame * CFrame.new(-.2,-.1,-.2)
				effect5.Parent = game.Workspace
		effect5.CFrame = humanoid.Parent["Right Leg"].CFrame * CFrame.new(.2,.2,.2)
		end
		for i = 1,10 do  wait(.05)
			effect.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect1.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect2.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect3.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect4.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect5.Size = effect.Size + Vector3.new(.5,.5,.5)

			
		end
			for i = 1,10 do  wait(.05)
			effect.Size = effect.Size + Vector3.new(.2,.2,.2)
			effect.Transparency = effect.Transparency + 0.05
				effect1.Size = effect.Size + Vector3.new(.2,.2,.2)
			effect1.Transparency = effect.Transparency + 0.05
			effect2.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect2.Transparency = effect.Transparency + 0.05

			effect3.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect3.Transparency = effect.Transparency + 0.05

			effect4.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect4.Transparency = effect.Transparency + 0.05

			effect5.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect5.Transparency = effect.Transparency + 0.05

				
			
			end
		end
		debris:AddItem(effect)
		debris:AddItem(effect1)
		debris:AddItem(effect2)
		debris:AddItem(effect3)
		debris:AddItem(effect4)
		debris:AddItem(effect5)
		
	end
		
end)

(if you also see any way I can improve my code please don’t forget to mention it)

4 Likes

I’m not very good at debugging the code of other developers, but I thought I would give this a shot. I apologize in advance if my solution does not work. I just thought I would mention a couple things that came to mind.

  1. First of all “effect” is created outside of your Touched event. Your other effects depend upon the size setting of the original, so, if I’m reading everything correctly, you would need to reset the size of “effect.” You could take care of the issue through an alternate method.

  2. Since “effect” is defined outside of the Touched event, it is not recreated every time the event is fired. However, you use Debris:AddItem(effect) which destroys the Instance. Since the size growth and transparency of the other effects depend upon the size and transparency of “effect”, the effects won’t “grow” or turn invisible. I believe this is the issue you are showing in your video. (As I’m writing this I had the thought that this should throw an error, but perhaps not.)

Let me know if this helps you. If not perhaps we can figure out another solution.

Hello I updated the script and put effect in the touch event


Targets = {}
debris = game:GetService("Debris")

script.Parent.Touched:Connect(function(hit)
	humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and hit.Parent.Name ~= _G.BEAMNAM then
	Character = hit.Parent
	if Targets[Character] == nil or tick() - Targets[Character] > 5 then
		effect = game.ReplicatedStorage.TOOLS.EFFECTS.BeamEffects:Clone()
		print("f")
		Targets[Character] = tick()
		humanoid.Health = humanoid.Health - 10
		humanoid.WalkSpeed = 5
		
	
		effect1 = effect:Clone()
		effect2 = effect:Clone()
		effect3 = effect:Clone()
		effect4 = effect:Clone()
		effect5 = effect:Clone()
	
		for i = 1,10 do 
		
		effect.Parent = game.Workspace
		effect.CFrame = humanoid.Parent.Torso.CFrame * CFrame.new(.3,.4,.6)
				effect1.Parent = game.Workspace
		effect1.CFrame = humanoid.Parent.Head.CFrame * CFrame.new(.2,.2,.2)
				effect2.Parent = game.Workspace
		effect2.CFrame = humanoid.Parent["Right Arm"].CFrame * CFrame.new(-.2,-.2,-.2)
				effect3.Parent = game.Workspace
		effect3.CFrame = humanoid.Parent["Left Arm"].CFrame * CFrame.new(.3,.6,.4)
				effect4.Parent = game.Workspace
		effect4.CFrame = humanoid.Parent["Left Leg"].CFrame * CFrame.new(-.2,-.1,-.2)
				effect5.Parent = game.Workspace
		effect5.CFrame = humanoid.Parent["Right Leg"].CFrame * CFrame.new(.2,.2,.2)
		end
		for i = 1,10 do  wait(.05)
			effect.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect1.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect2.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect3.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect4.Size = effect.Size + Vector3.new(.5,.5,.5)
			effect5.Size = effect.Size + Vector3.new(.5,.5,.5)

			
		end
			for i = 1,10 do  wait(.05)
			effect.Size = effect.Size + Vector3.new(.2,.2,.2)
			effect.Transparency = effect.Transparency + 0.05
				effect1.Size = effect.Size + Vector3.new(.2,.2,.2)
			effect1.Transparency = effect.Transparency + 0.05
			effect2.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect2.Transparency = effect.Transparency + 0.05

			effect3.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect3.Transparency = effect.Transparency + 0.05

			effect4.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect4.Transparency = effect.Transparency + 0.05

			effect5.Size = effect.Size + Vector3.new(.2,.2,.2)
						effect5.Transparency = effect.Transparency + 0.05

				
			
			end
		end
		debris:AddItem(effect)
		debris:AddItem(effect1)
		debris:AddItem(effect2)
		debris:AddItem(effect3)
		debris:AddItem(effect4)
		debris:AddItem(effect5)
		
	end
		
end)

It still has the same outcome.

1 Like

Hmmm. So just to clarify, the issue only occurs when two targets are hit simultaneously? If the effect ends and then is activated again, it works? I’m not at my computer right now, but if you don’t mind, I might try playing around with your code that you posted in a bit, and see what happens.

Yea the issue occurs only when the targets are hit simultaneously, feel free to mess around with it.

So I tested the script, and it seems to work for me. This makes me think that the issue you are having might not be with this specific script. Perhaps there is something else in your game that is causing the issue? Here is the place file in which I tested it:
Testing.rbxl (22.2 KB)

EDIT: Also, are you receiving any error messages when this bug occurs?

1 Like

No errors, I will try messing around with the code later in different games. Thank you for the help.

1 Like

Yeah, no problem. I feel sorry that we couldn’t come to a definite resolution on this. Like I mentioned before, I don’t believe the issue is with this specific script, but I may be wrong. If you have any more questions or information to add, don’t hesitate to ask. Good luck!

I believe its with the main beam script, I tried messing around with it in a different place with just the damage script and the beam script, but did not manage to fix it. I attached a place copy if you’d like to check it out.

Test.rbxl (50.0 KB)

1 Like

Awesome! Alright, I think I fixed it. I put “local” in front of your variables in the “dmg” script, and I moved the Debris:AddItem() functions inside of the if statement. So the issue might have actually been with the original script after all. Being able to see the bug occurring and work with it at the same time was very helpful, thank you!
Here is the updated place file: TestFixed.rbxl (50.0 KB)

1 Like

Thanks for the help, it worked, and also happy thanksgiving!

1 Like

Awesome! Glad I could help! Happy Thanksgiving to you too!