How would i correctly identify the player character model in a touched event?

so in my hitbox system i use a touched event on my hitbox part along with the argument other for the part touched and say that the player character touched is other.Parent . this usually returns errors when im trying to do something like model:FindFirstChildOfClass(“Humanoid”) because it detects all sorts of baseparts in the model, like accesories. what is the best way to only register one of the 7 body parts of the r6 character? (6 + HumanoidRootPart)
(yes, this might be an easy question, but i cant think of anything)

3 Likes

if i understand this post correctly, then you’re dealing with the same issue i was dealing with.

the fix to this is:

local table = {}

x.Touched:Connect ...

local target = -- your target

if table.find(table, target) then return end -- or continue if you're using a for loop

table.insert(table, target)

-- and after everything is done (cooldowns or anything)

table.remove(table, target) or table = {} -- if you're using a for loop, use the table = {} outside the for loop, otherwise it will not work

if i misunderstood this please tell me so i’m not throwing useless help attempts :smiley: :+1:

3 Likes

my issue isnt a hitlist, my issue is that when i do

part.Touched:Connect(function(other)
local character = other.Parent
end)

character isnt always the player model, but most of the time a bodypart, or an accesory (alr tried setting canTouch of all baseparts with cancollide off from the character and still didnt fix the issue)

2 Likes

hmm

what about this?

part.Touched:Connect(function(other)

if other.Parent:FindFirstChild("Humanoid") or other.Parent:FindFirstChild("Character") then -- i'm not sure if :FindFirstChild("Character") will work
local character = other.Parent
end)

this should work, since that variable gets created once the part finds a humanoid

2 Likes

you can use Players:GetPlayerFromCharacter(character), if the player does not exist, the character is not a player character.

2 Likes

it was this easy

local model
			if other.Parent:IsA("Model") then
				model = other.Parent
			end
			if not model then return end
2 Likes