local ReplicatedStorage = game:GetService("ReplicatedStorage")
local zombieFlingEvent = ReplicatedStorage:WaitForChild("ZombieFlingEvent")
zombieFlingEvent.OnServerEvent:Connect(function(player)
print("Received event")
local character = player.Character
if not character then return end
local swordHitbox = character:FindFirstChild("SwordHitbox")
if not swordHitbox or not swordHitbox:IsA("Part") then
print("SwordHitbox not found!")
return
end
swordHitbox.CanCollide = false
swordHitbox.CanTouch = true
for _, touchingPart in ipairs(swordHitbox:GetTouchingParts()) do
print("Checking touching parts...")
local parentModel = touchingPart:FindFirstAncestorOfClass("Model")
if parentModel and parentModel:FindFirstChild("Humanoid") and parentModel.Name == "Zombie" then
local rootPart = parentModel:FindFirstChild("HumanoidRootPart")
if rootPart then
rootPart.AssemblyLinearVelocity = rootPart.AssemblyLinearVelocity + Vector3.new(0, 50, 0)
print("Zombie flung!")
end
end
end
end)
I mean, the API does say :GetTouchingParts() will return a table of all BasePart.CanCollide true parts that intersect with it so this is intentional.
However, I found that there is a workaround to this: if you have an empty .Touched event and disconnect it after, it will return the touching parts.
This is because of (I believe) something to do with the .Touched event interfering with the parts’ physics, making it behave differently and being prone to collision.
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local touchingParts = GetTouchingParts(workspace.TestPart1)
print(touchingParts) --> Table with the touching parts