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.
Hello. This has a really simple fix.
Problem:
Solution:
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)