How to make hitbox detect 1 person only?

  1. What do you want to achieve? Keep it simple and clear!
    Trying to make a hitbox only detect 1 person.

  2. What is the issue? Include screenshots / videos if possible!
    My issue is that my hitbox detection system is somewhat unique. It utilizes the ‘workspace:GetPartBoundsInBox()’ function and is designed to detect ‘CharacterHitboxes’ (a folder in workspace containing all the hitboxes of the players in game) . Inside this folder, there is a part that is welded to a player’s HumanoidRootPart when they join the game. Each Hitbox (welded part) contains an ObjectValue, which value is the character the hitbox is welded to, and when a raycast intersects with this hitbox, it’s supposed to identify the associated player and apply damage. However, I’m uncertain about how to make it work for only one player at a time.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve checked out the Roblox Dev Forum and tried a little experiment of my own. Basically, I’m keeping track of players in a list and making sure it doesn’t go beyond one player. The idea is to only deal damage to those in the list. I also played around with some other ideas, but I can’t remember all the specifics right now.

local hitboxSize =  Vector3.new(3.5, 3.5, 3)	

for i=1,5 do
			local pos =  RootPart.CFrame * CFrame.new(0,0,-2)	
			
			if Character.Humanoid.MoveDirection.Magnitude >0 then
				pos = pos * CFrame.new(1,0,-1) 
				hitboxSize = hitboxSize + Vector3.new(1,0,-1)
			end

			local partsInRegion = workspace:GetPartBoundsInBox(pos,hitboxSize,params)

			for _,v in pairs(partsInRegion) do
				if v and v.Character.Value ~= Character then
		            local target = v.Character.Value

					task.spawn(serverfunctions.dmg,Character,target)
				end
			end
			task.wait(.05)
		end

I’m not sure i quite understood your situation, but perhaps one of these can achieve your goal:

List of players to damage

(Replace charactersToDamage with your own list, and add the damage code at the comment)

local partsInRegion = workspace:GetPartBoundsInBox(pos, hitboxSize, params)

local charactersToDamage = {workspace:WaitForChild("bruh_specialist")}

local damagedCharacters = {}
for _, char in charactersToDamage do
	damagedCharacters[char] = false
end

for _,v in pairs(partsInRegion) do
	local characterInRegion = (function()
		local char = v:FindFirstAncestorWhichIsA("Model")
		if char and game.Players:GetPlayerFromCharacter(char) then
			return char
		end
	end)()
	
	if damagedCharacters[characterInRegion] == false then
		--characterInRegion is in list and can be damaged at this point
		damagedCharacters[characterInRegion] = true
	end
end
Single player to damage

(Replace characterToDamage with desired player character, and like before, add code to damage the player at the comment)

local partsInRegion = workspace:GetPartBoundsInBox(pos, hitboxSize, params)

local characterToDamage, characterDamaged = workspace:WaitForChild("bruh_specialist"), false

for _,v in pairs(partsInRegion) do
	local characterInRegion = (function()
		local char = v:FindFirstAncestorWhichIsA("Model")
		if char and game.Players:GetPlayerFromCharacter(char) then
			return char
		end
	end)()
	
	if characterInRegion == characterToDamage and characterDamaged == false then
		--characterInRegion/characterToDamage can be damaged at this point
		characterDamaged = true
	end
end

Note that none of these methods use the hitbox part of the players