Table Humanoid and HumanoidRootPart checker/finder

Hi I wanted to ask, if I can check the children of a folder in workspace for humanoids and humanoidrootparts so my combat tool script damages them. I use dot product. I just wanna know if its possible and what the best way to go about it would be. I tried using a table but I’m just getting a little confused on how I would even be making it.

Ps: the table can already list whats in the folder (I put all players and killable npc’s inside it)

my code:

local ppl = game.Workspace.Live:GetChildren()
for i,v in pairs(ppl) do
	print(v.Name)
end

 tool.Activated:Connect(function()
 	if debouce then return end
 	local Hum=ppl:FindFirstChild("Humanoid")
 	if (workspace.Live.Dummy.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude > 7 then return end
	local entVector = (workspace.Live.Dummy.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Unit
 	if player.Character.HumanoidRootPart.CFrame.lookVector:Dot(entVector) < 0.7 then return end
 	print("hurra! Du darfst gewalt praktizieren")
 	workspace.Live.Dummy.Humanoid:TakeDamage(10)
	debouce = true
 	wait(0.2)
		debouce = false
 end)

ignore the local hum=ppl:FindFirstChild

local part = parent:FindFirstChild("name")
if part then
    doStuff()
end

Is this what you want? This function returns all the humanoides on the characters on the folder on the workspace.

local ppl = game.Workspace.Live

local humanoids = {
	
}

function GetHumanoids(ppl, humanoids)
	for i,v in pairs(ppl:GetDescendants()) do
		if v:IsA("Humanoid") then
			table.insert(humanoids, v)
		end
		return v
	end
end

What I want basically is
When you activate the tool it checks in a bound radius around you if theres any children
from the workspace.Live folder. IF it finds a child from the workspace.Live folder it returns the Childs info so I can access it. Its kind of hard to explain because my brain is a tad foggy at the moment. What I need is for the script to find the child of workspace.Live so I can access its humanoidrootparts position and humanoid to:
Damage it
And Find out if it even is inside the radius.
If you know a better way on how to use DotProduct as a hitbox pls let me know.

No no not like that the script is inside a tool thats inside the character that needs to check a the children of a folder inside workspace for them. IF they are even inside the radius.

If i understood, this would be the thing you are looking for.
It may have issues because I made it out of the studio and didn’t test

local ppl = game.Workspace.Live:GetChildren()
local player = game:GetService("Players")
for i,v in pairs(ppl) do
	print(v.Name)
end

tool.Activated:Connect(function()
	if debouce then return end
	
	for i,v in pairs(ppl) do
		if (ppl.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <= 7 then
			local HumanoidRootPart = ppl.HumanoidRootPart
			local Humanoid = ppl.Humanoid
		end
	end
end)

hope THIS is what you are looking for

Great let me check it and see if it helps. Thank you for taking the time to write it beforehand!

You should use ipairs for getchildren instead of pairs since it isn’t formatted with an iterator.

Whilst you’re at correcting, for the purpose of me learning, Do you care to explain what an iterator is??

It says
Combat.combobat:17: attempt to index nil with ‘Position’ - Server - combobat:17
Which is this line

if (ppl.HumanoidRootPart.Position -player.Character.HumanoidRootPart.Position).magnitude <= 7 then

Sure. When looping through instances, there are 2 types of loops. The first is just “for v (value) in table do”, the second is “for i (iterator),v (value) in pairs(table) do” or “for i (iterator),v (value) in ipairs(table) do”. The iterator is the index of the value (the position of the value in the table). If the table doesn’t have an iterator formatted already ([1] = “value”) then you have to use ipairs() to format it that way.

1 Like

Well, I think that the problem is in the folder. Is there something in the folder which is not a character?
also try to: Print(ppl.HumanoidRootPart)

1 Like

I didn’t knew ipairs(), thanks

2 Likes

It prints nil for some reason…

That means the humanoid does not exist.

1 Like

which means that now you have to fix the folder

1 Like

So can I check if the Humanoid exists and if it does then execute damage and stuff??

image
this is what the folder looks like when Im playtesting

1 Like

Do they all have a HumanoidRootPart?

1 Like