so basically, im using a hitbox thats a circle and using GetTouchingParts to find the players in the circle.
it works however it only gets 1 player, not all of the players in the radius. so how should i get all players in the radius instead of 1?
(im using a custom GetTouchingParts function that also detects parts of which have CanCollide set to false)
function if needed:
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
code that gets the players in the radius:
local PartsInRadius = GetTouchingParts(car.ExplosionRadius)
for i, v in pairs(PartsInRadius) do
if v.Parent:FindFirstChild("Humanoid") and v ~= car:GetDescendants() and not db then
db = true
print(v.Parent.Name) --only prints one player
end
end
That’s because of the debounce. You are not letting it pass that if statement more than once.
and not db then
db = true
Use this function
local function GetTouchingCharacters(touchPart)
local connection = touchPart.Touched:Connect(function() end)
local touching = touchPart:GetTouchingParts()
connection:Disconnect()
local characters = {}
local results = {}
for _, part in pairs(touching) do
if part.Parent:FindFirstChild("Humanoid") then
if not characters[part.Parent] then
characters[part.Parent] = true
table.insert(results, part.Parent)
end
end
end
return results
end
That should just give you a list of characters that are touching the part.
sorry but how would i get the table from the function into this??:
local PartsInRadius = GetTouchingCharacters(car.ExplosionRadius)
for i, v in pairs(PartsInRadius) do
if v.Parent:FindFirstChild("Humanoid") and v ~= car:GetDescendants() then
print(v.Parent.Name)
print("e")
--db = true
end
end
(im trying to get all of the players that were touching the part, and then dmg them/ragdoll)
v is the character in your example. You no longer have to check for a humanoid. In fact it’s likely not working because you are. Humanoid would be a child now not a sibling. The function returns a list of all characters who had at least one part in the radius.
I’ve renamed what you had as v to character in this example, but you should be able to use this instead of the loop you gave.
local CharsInRadius = GetTouchingCharacters(car.ExplosionRadius)
for _, character in pairs(CharsInRadius) do
character.Humanoid:TakeDamage(65)
end