This code below works - but can lag up studio by rapidly calling it.
local Hitbox = GhostObject:FindFirstChild("Hitbox")
if Hitbox then
Hitbox.CanCollide = true
for i, v in pairs(Hitbox:GetTouchingParts()) do
for index, value in pairs(v.Parent:GetChildren()) do
if value.Name == "Hitbox" then
IsColliding = true
end
end
end
Hitbox.CanCollide = false
end
I have had to use two for i, v in pairs loops because for some reason, GetTouchingParts() cannot return the name, in v.Name, For example this won't work:
if v.Name == "Hitbox" then -- since v.Name is apparently the type
IsColliding = true
end
Is there another way to obtain the same result but without the second loop?

1 comment
bootsiels answer should work fine but a note for the future for you there is a method called FindFirstChild() and it does the same thing