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)