Help me with Touched Hitbox pls

Hitbox do 7 time damage:
image

here code:

local Rp = game:GetService("ReplicatedStorage")
local Sounds = Rp:WaitForChild("Sounds")
local BattleSounds = Sounds:WaitForChild("BattleSound")
local event = Rp:WaitForChild("Remotes").Dash

local animations = Rp:WaitForChild("Animations")

local function getDMGanimators(eHum)
	local getDmgAnimation = animations.Extra

	local one = getDmgAnimation.GetDMG1
	local two = getDmgAnimation.GetDMG2
	local three = getDmgAnimation.GetDMG3
	local four = getDmgAnimation.GetDMG4

	local getDMGanims = {
		['One'] = one,
		['Two'] = two,
		['Three'] = three,
		['Four'] = four
	}

	local randomAnim = math.random(1,4)
	if randomAnim == 1 then
		eHum:LoadAnimation(getDMGanims.One):Play()
	elseif randomAnim == 2 then
		eHum:LoadAnimation(getDMGanims.Two):Play()
	elseif randomAnim == 3 then
		eHum:LoadAnimation(getDMGanims.Three):Play()
	elseif randomAnim == 4 then
		eHum:LoadAnimation(getDMGanims.Four):Play()
	end

end

local function onDashEvent(Player)
	local char = Player.Character
	local hrp = char.HumanoidRootPart

	local hitboxtime = .1

	local hitbox = Instance.new("Part", hrp)
	hitbox.Size = Vector3.new(7,6,6)
	hitbox.CanCollide = false
	hitbox.Massless = true
	hitbox.Transparency = 0
	hitbox.Material = 'ForceField'

	wait(0.5)

	local weldz = Instance.new("Weld", hitbox)
	weldz.Part0 = hrp
	weldz.Part1 = hitbox
	weldz.C1 = CFrame.new(-0.000244140625, 4.76837158e-07, 2.99987793, 1, 0, 0, 0, 1, 0, 0, 0, 1)

	game.Debris:AddItem(hitbox, hitboxtime)

	local damaged = {}
	local connection

	connection = hitbox.Touched:Connect(function(v)
		local eChar = v.Parent

		if eChar ~= char and eChar:FindFirstChild("Humanoid") and not damaged[eChar] and eChar:GetAttribute('Blocking') == false then
			
			local eHum = eChar.Humanoid
			eHum:TakeDamage(4)
			print('Humanoid Take damage!')
			
			
			local sound = BattleSounds:FindFirstChild("Punch1"):Clone()
			sound.Parent = eChar.HumanoidRootPart
			sound:Play()
			game.Debris:AddItem(sound, 1)
			
		elseif eChar ~= char and eChar:FindFirstChild("Humanoid") and not damaged[eChar] and eChar:GetAttribute('Blocking') == true then
			
			local eHum = eChar.Humanoid
			eHum:TakeDamage(0)
			print('Humanoid Block Attack!')
			
			local sound = BattleSounds:FindFirstChild("BlockPunch4"):Clone()
			sound.Parent = eChar.HumanoidRootPart
			sound:Play()
			game.Debris:AddItem(sound, 1)
		end
		
	end)
	
end

event.OnServerEvent:Connect(onDashEvent)

You made the connection but didn’t disconnect it

You’re creating a new connection every time onDashEvent is run so each connection will continue to listen for the .Touched event, causing it to fire multiple times. So you have to disconnect it

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