Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't SubtractAsync() CSG Negate?

game.Players.PlayerAdded:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()
    local hitboxClone = game.Workspace.Hitbox:Clone()
    
    hitboxClone.Parent = char
    hitboxClone.Position = char.HumanoidRootPart.Position
    hitboxClone.Anchored = false
    hitboxClone.Name = "PlayerHitbox"
    
    local weld = Instance.new("Weld",hitboxClone)
    weld.Part0 = char.HumanoidRootPart
    weld.Part1 = hitboxClone
    
    hitboxClone.Touched:Connect(function(hit)
        if hit.Name == "Subtract" then
            local SubtractClone = hitboxClone:Clone()
            SubtractClone.Parent = game.Workspace
            SubtractClone.Anchored = false
            SubtractClone.Name = "SubtractHitbox"
            
            local parts = {hit}
            local SubtractUnion = SubtractClone:SubtractAsync(parts)
            SubtractClone:Destroy()
        end
    end)
end)

Nothing here throws an error, the clones work, it just won't do the CSG.

4 comments

0

"The resulting PartOperation is always un-parented and based on positions of the parts as they were when the operation was started." tl;dr parent SubtractUnion to Workspace

0

All that does is make the parts clone but not Negate

0

Destroy hitboxClone, too.

0

But I need the hitbox clone to exist stay welded on the player

1 answer

✓ Accepted answer

Hello. This has a really simple fix.


Problem:

  • You forgot to parent the union to Workspace.

Solution:

  • Parent it to Workspace by using SubtractUnion.Parent = workspace.

Recommendations:

  • Use a WeldConstraint since it doesn't require the "C0" and "C1" properties.

  • Don't use the second argument of Instance.new(). It's inefficient and causes lag. Instead, set it manually by using weld.Parent = hitboxClone.


Fixed Code:

game.Players.PlayerAdded:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()
    local hitboxClone = game.Workspace.Hitbox:Clone()

    hitboxClone.Parent = char
    hitboxClone.Position = char.HumanoidRootPart.Position
    hitboxClone.Anchored = false
    hitboxClone.Name = "PlayerHitbox"

    local weld = Instance.new("WeldConstraint")
	weld.Part0 = char.HumanoidRootPart
    weld.Part1 = hitboxClone
	weld.Parent = hitboxClone

    hitboxClone.Touched:Connect(function(hit)
        if hit.Name == "Subtract" then
            local SubtractClone = hitboxClone:Clone()
            SubtractClone.Parent = game.Workspace
            SubtractClone.Anchored = false
            SubtractClone.Name = "SubtractHitbox"

            local parts = {hit}
            local SubtractUnion = SubtractClone:SubtractAsync(parts)
            SubtractClone:Destroy()

		SubtractUnion.Parent = workspace
        end
    end)
end)

1 comment

0

Did that, now it just creates a ton of Clones but no CSG

This discussion is preserved as it was. New answers, comments, and votes are closed.