Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why won't SubtractAsync() CSG Negate?

Asked by 3 years ago
Edited 3 years ago
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.

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 y3_th 176 — 3y
0
All that does is make the parts clone but not Negate zboi082007 270 — 3y
0
Destroy hitboxClone, too. y3_th 176 — 3y
0
But I need the hitbox clone to exist stay welded on the player zboi082007 270 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
Did that, now it just creates a ton of Clones but no CSG zboi082007 270 — 3y
Ad

Answer this question