Hello! I’m having a problem using the SubtractAsync() method, where despite no errors or warnings would show up in the output, calling it has always resulted in nothing. I’ve tried looking through the documentation and searching other posts but nothing has worked.
I’ve been trying to create a hitbox for my explosion which fires whenever a player presses a specific button, and if that hitbox had any parts intersecting it, the localscript will fire an UnreliableRemoteEvent which will then be picked up by a server script for it to deform the parts.
LocalScript excerpt (located in StarterCharacterScripts)
local explosion = Instance.new("Explosion")
explosion.Position = mouse.Hit.Position
explosion.Parent = workspace
explosion.DestroyJointRadiusPercent = 0
explosion.BlastRadius = 12
local part = Instance.new("Part")
part.Size = Vector3.new(12,12,12)
part.Transparency = 1
part.Anchored = true
part.Position = mouse.Hit.Position
part.Shape = Enum.PartType.Ball
part.Parent = workspace
for index, one in part:GetTouchingParts() do
if not one:HasTag("invincible") then
replicatedstorage.Events.DestroyPart:FireServer(one, mouse.Hit.Position)
end
end
part:Destroy()
ServerScript excerpt (located in ServerScriptService)
events:WaitForChild("DestroyPart").OnServerEvent:Connect(function(plr, victim, mousepos)
local part = Instance.new("Part")
part.Shape = Enum.PartType.Ball
part.Anchored = true
part.Position = mousepos
part.Size = Vector3.new(12,12,12)
part.Parent = workspace
local ogname = victim.Name
local success, err = pcall(function()
victim:SubtractAsync({part})
print("called ".. victim.Name .." to be subtracted by ".. part.Name)
end)
if err then
error(err)
elseif success then
print("success")
end
if victim:IsA("UnionOperation") then
print("union successful")
victim.CollisionFidelity = Enum.CollisionFidelity.PreciseConvexDecomposition
end
victim.Parent = workspace
victim.Name = ogname
part:Destroy()
end)
Output:
Part that was sent through the remote on client vs server:
I’ve heard that the API used in SubtractAsync() and other methods is very buggy and may lead to unexpected results, so if there are any replacements for it please tell me so!
As for solving it on my own, I’ve tried removing the part:Destroy() line on the server script to see if the part wasn’t actually touching or if the method didn’t finish before the part was destroyed, but that wasn’t the case.
Thank you for your help!