Need help with GetPartsBoundInBox

So I’m making a combat system and I chose to use spatial querys for my hitboxes, but my main problem is that it detects multiple body parts of a character and damages them all. This is an easy fix as I just made a table and I check if the hitparts Parent (character) is already in it and if not then I damage the players humanoid once and then add their character to the table. However this seems to not work and I don’t know why anyone have an idea?

code

local hitEvent = game.ReplicatedStorage.Combat.hitEvent
local block = require(script.Block)

hitEvent.OnServerEvent:Connect(function(plr : Player, data)
	if data.Action == "Hit" then
		if next(data.Hits) then
			local humsHit = {} 
			for _, hit in pairs(data.Hits) do
				if hit.Parent:FindFirstChildOfClass("Humanoid") and not humsHit[hit.Parent] and hit.Parent ~= plr.Character then
					humsHit[hit.Parent] = true
					
					hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(10)
					
				end
			end

		end
	end
end)
1 Like

You can add a condition, if the Hits value/data has more than 1 body part hit on that character, return/stop early and not deal any damage.

That is essentially what I’m doing by putting the players character that has been hit inside the table and checking if it’s in the table each time but it won’t work and I don’t know why

you can do somethings like this:

for _, hit in pairs(data.Hits) do
				if hit.Parent:FindFirstChildOfClass("Humanoid") and not table.find(humsHit, hit.Parent) and hit.Parent ~= plr.Character then
					table.insert(humsHit, hit.Parent) 

					if #data.Hits > 1 then return end		

                hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(10)	
				end
			end

You also need to clear the table after each attack, so it doesn’t overlap and keeps working after the first one.

OP already has implemented a solution to stop a character from being hit multiple times within a single Hit event.

What is the client-side script that is firing this event? Is the client-side script firing it multiple times for every part it hit?

Also, it looks like you are doing 0 server-side checks to ensure that the hit was valid. Do note that exploiters can easily take advantage of this and make map-wide kill auras in your game.

I just started to work on this and my plan is to add the checks once I actually get it to work
And yes I am looking into the client I think the issue might be that it’s firing the event repeatedly but I don’t know how yet so I’ll mark you with solution if I find it.

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