Hitbox interfering with itself

For some context, this weapon uses ClientCast, a hitbox module, although it’s not the fault of the module this is happening.

Basically what should happen is that it begins drawing rays upon clicking, which it does however the problem is the way I wrote the script will override the hitbox if you click in succession, this is pretty awkward to describe in words so I will show a video:

as you can see the rays cut themselves off, here is the block of code

	Hitbox.HumanoidCollided:Connect(function(result, hit)
		
	
		local enemyhum = hit.Parent:FindFirstChild("Humanoid")
		if enemyhum == nil or enemyhum.Parent == Character or enemyhum.Health <= 0 then return end
		if Debounce[hit] then return end
		Debounce[hit] = true
		enemyhum:TakeDamage(10)
		--Hitbox:Stop()
		--task.spawn(HighlightTarg)
		--SoundModule.PlaySound(Sounds.Hit, Blade)
		task.wait(.3)
		Debounce[hit] = false
	end)

	Hitbox:Start()
	task.spawn(WeightedAttack)
	task.wait(0.5)
	--if Hitbox == nil then return end
	Hitbox:Stop()
	
	
end

I’m quite sure the issue takes place toward the bottom, the part where it starts to draw and then stop the rays after a timer, however the timer bleeds into the next click and cuts the next hitbox off early.

A solution that does work but is very unsatisfactory is making the hitbox timer less than the time between slashes

2 Likes

Sorry for bad formatting I’m on mobile. But just tracking the tick() of when it’s activated should be enough to solve your issue.

local lastActive = 0
Hitbox.HumanoidCollided:Connect(function(result, hit)
		
	local thisActive = tick()
        lastActive = thisActive


		local enemyhum = hit.Parent:FindFirstChild("Humanoid")
		if enemyhum == nil or enemyhum.Parent == Character or enemyhum.Health <= 0 then return end
		if Debounce[hit] then return end
		Debounce[hit] = true
		enemyhum:TakeDamage(10)
		--Hitbox:Stop()
		--task.spawn(HighlightTarg)
		--SoundModule.PlaySound(Sounds.Hit, Blade)
		task.wait(.3)
		Debounce[hit] = false
	end)

	Hitbox:Start()
	task.spawn(WeightedAttack)
	task.wait(0.5)
if thisActive == lastActive then
	--if Hitbox == nil then return end
	Hitbox:Stop()
end
	
end
2 Likes

Thank you! I completely forgot I could do this.

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