ClientCast hitbox requires movement to damage

Hi,

I’m using clientcast for my game but one issue I stumbled upon was that clientcast does not do damage unless movement is being involved. How would I fix that issue inside the humanoid collision connection?


local function onHumanoidCollidedAsync(RaycastResult: RaycastResult, HitHumanoid: Humanoid, character)
	if HitHumanoid == character.Humanoid then return end
	if HitHumanoid.Health == 0 then return end

	if Debounce[HitHumanoid] then
		return
	end

	Debounce[HitHumanoid] = true

	HitHumanoid:TakeDamage(Settings.RangeDamage)

	local newBlood = Blood:Clone()

	for _, instance in pairs(newBlood:GetChildren()) do
		local root = HitHumanoid.Parent.HumanoidRootPart

		if instance:IsA("ParticleEmitter") then
			instance = instance :: ParticleEmitter

			instance.Parent = root
			instance:Emit(instance:GetAttribute("EmitCount"))

			Debris:AddItem(instance, instance.Lifetime.Max)
		end

		if instance:IsA("Sound") then
			instance = instance :: Sound
			PlaySound(instance, root)
		end
	end

	task.wait(Settings.RangeCooldown)
	Debounce[HitHumanoid] = false
end

You have to emit rays for it to deal damage. Touched forces movement to occur. Raycasting does not. So if it is raycasting then it’s only firing rays based on touch which is not the right way to go about it

local function UpdateAttachment(Attachment, Caster, LastPositions)
	local CurrentPosition = Attachment.WorldPosition
	local LastPosition = LastPositions[Attachment] or CurrentPosition
	
	if CurrentPosition ~= LastPosition then
		local RaycastResult = workspace:Raycast(LastPosition, CurrentPosition - LastPosition, Caster.RaycastParams)

		UpdateCasterEvents(Caster, RaycastResult)
	end

	LastPositions[Attachment] = CurrentPosition
end

Clientcast does use rays but I use clientcast for lagless combat. There has to be a way to maybe do a repeat check inside the connection onHumanoidCollided

Are you trying to melt the enemy down to zero health once they’ve collided? Or are you strictly abiding by the query where they must continue colliding with the enemy per hit? I know what to do either way just tell me which one you’re going for

1 Like

I just made my own hotbox module, since it only works when it moves I only used it for constantly moving hitboxes such as projectiles.

They must continue colliding with the enemy per hit. If the enemy is inside the hitbox without movement I want that to be detected and do damage

1 Like

I didn’t understand that message

Okay great so for this one what you will learn in coding is how to do something until a condition is met. In this case, we’re trying to meet the condition where the humanoid is dead, but the actions we do to get the humanoid to reach that condition, in this case, is repeating the behavior where it will apply damage while the enemy is inside the hitbox. You have to find the area where it fires the raycast, and repeat it until humanoid health is 0, but you’re only doing it after they’ve already interacted with the enemy, so you need to account for that. This makes it so that it isn’t unnecessarily firing, and it’s only firing the raycasts when there’s already been an interaction between the two

I just explained the first option, the second one would be to melt the enemy to 0 health after an interaction occurred, even if the enemy isn’t actively colliding. It’s easier because with that option, all you would have to do is repeat the damage until it kills the enemy

1 Like

From what you said, I suppose you use .Touched
If so, I recommend you use this if you want it damage without target moving

(Its workspace:GetPartsInPart as I remember)

ClientCast should probably be used if you want extremely precise hitboxes. The attack looks like a plain shape, and the attachments shown are just a line. You’re probably better off using spatial queries.

I’m not very familiar with spatial queries, and the main reason I tried to use clientcast was because when someone who was controlling the hitbox had higher ping, it would look like they had higher reach and vice versa. It’s a latency issue that I was trying to solve.

1 Like

Here’s the solution for anyone who’s interested. Still has some issues but fixed the main problem:

local function onHumanoidCollidedAsync(RaycastResult: RaycastResult, HitHumanoid: Humanoid, character, range: Part)
	if HitHumanoid == character.Humanoid then return end
	if HitHumanoid.Health == 0 then return end

	if Debounce[HitHumanoid] then
		return
	end

	Debounce[HitHumanoid] = true
	
	HitHumanoid:TakeDamage(Settings.RangeDamage)
	
	local Params = OverlapParams.new()
	
	Params.FilterType = Enum.RaycastFilterType.Exclude
	Params.FilterDescendantsInstances = {character}
	
	repeat
		local table = workspace:GetPartsInPart(range, Params)
		HitHumanoid:TakeDamage(Settings.RangeDamage)
		damagePlayer(HitHumanoid)
		
		task.wait(Settings.RangeCooldown)
	until HitHumanoid.Health == 0 or not isInside(table, HitHumanoid.Parent)

	Debounce[HitHumanoid] = false
end
2 Likes

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