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)
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)
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.