My script is duplicating something way more times than I need to

I am confused why this script is duplicating this part too many times is there anyone who can help me with this
—Script----

local UIS = game:GetService("UserInputService")
local module = {}
local db = false
local ShockClone
local WeldConst

function module:Activate(Plr,Humanoid:Humanoid)
	local Keycode = Enum.KeyCode.E
	local Animation = script:FindFirstChild("Ice Barrage")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	local Track = Animator:LoadAnimation(Animation)
	local Char = Plr.Character or Plr.CharacterAdded:Wait()
	
	UIS.InputBegan:Connect(function(inp,gpe)
		if gpe then return end
		
		if inp.KeyCode == Enum.KeyCode.E  and not db then
			db = true
			Track:Play()
			Track:GetMarkerReachedSignal("Blast"):Connect(function()
				 ShockClone = game.ReplicatedStorage.Shock:Clone()
			    WeldConst = Instance.new("WeldConstraint")
				WeldConst.Parent = Char:WaitForChild("Right Arm")
				ShockClone.Parent = workspace
				ShockClone.CanCollide = false
				ShockClone.Anchored = true
				ShockClone.Position = Char:WaitForChild("Right Arm").Position
			end)
			Track.Ended:Connect(function()
				ShockClone:Destroy()
				task.wait(1)
				db = false
			end)
		end
				
	end)
	
end

return module

—Video—
https://gyazo.com/8bf92f6376879034d984ac2f6f9b08d8

It’s because you are not disconnecting this connection

What happens is since this connection is not being disconnected, every time InputBegan is fired it creates a new event GetMarkerReachedSignal and they get called each time this event fires.

Track:GetMarkerReachedSignal("Blast"):Connect(function()

You can use :Once instead of :Connect

Track:GetMarkerReachedSignal("Blast"):Once(function()
1 Like

Thanks this really helped alot

1 Like

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