Hi, this is my first forum post
I Created a tool that takes out chunks of any part using Subtract async which turns the part into a union. The problem is that sometimes (Usually when a lag spike occurs) it creates two unions instead of 1. This is bad because it creates Z-Fighting.
LocalScript:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Up:Connect(function()
if mouse.Target.Name == "Negate" then return end
if mouse.Target then
local Distance = (mouse.Hit.Position - player.Character.HumanoidRootPart.Position).Magnitude
if Distance <= 40 then
local MousePos = mouse.Hit.Position
local Material = mouse.Target.Material
local Color = mouse.Target.BrickColor
local Target = mouse.Target
script.Parent.Hit:FireServer(MousePos, Material, Color, Target)
end
end
end)
ServerScript:
local random = Random.new()
local Size = random:NextNumber(0.1, 0.3)
local State = false
local Particles = 30
script.Parent.Equipped:Connect(function()
State = true
end)
script.Parent.Unequipped:Connect(function()
State = false
end)
script.Parent.Hit.OnServerEvent:Connect(function(Player, MousePos, Material, Color, Target)
if State == false then return end
local DamageSize = random:NextNumber(0.5, 5)
local Sound = {}
for i,v in pairs(script.Parent.Sounds:GetChildren()) do
if v:IsA("Sound") then
table.insert(Sound,v)
end
end
local RandomSound = Sound[math.random(1,#Sound)]
RandomSound:Play()
--Particles
local Part1 = Instance.new("Part")
Part1.Size = Vector3.new(Size, Size, Size)
Part1.Parent = game.Workspace
Part1.Material = Material
Part1.BrickColor = Color
Part1.CanCollide = false
Part1.CastShadow = false
Part1.CanTouch = false
local Negate = Instance.new("Part")
Negate.Name = "Negate"
Negate.Parent = game.Workspace
Negate.Size = Vector3.new(DamageSize, DamageSize, DamageSize)
Negate.Position = Vector3.new(MousePos.X, MousePos.Y, MousePos.Z)
Negate.Transparency = 1
Negate.CanCollide = false
Negate.Anchored = true
Negate.CanTouch = false
-- Negate
local newSubtract = Target:SubtractAsync({Negate})
Negate:Destroy()
Target:Destroy()
newSubtract.Position = Target.Position
newSubtract.Parent = game.Workspace
newSubtract.UsePartColor = true
local Explosion = Instance.new("Explosion")
Explosion.Parent = game.Workspace
Explosion.Position = Vector3.new(MousePos.X, MousePos.Y, MousePos.Z)
Explosion.DestroyJointRadiusPercent = 0
Explosion.Visible = false
Explosion.BlastPressure = 40000
Explosion.BlastRadius = 5
--Spawn Particles
for i = 1, Particles do
Part1.Position = Vector3.new(MousePos.X + random:NextNumber(-1, 1), MousePos.Y + random:NextNumber(-1, 1), MousePos.Z + random:NextNumber(-1, 1))
Part1:Clone().Parent = game.Workspace
end
end)
When you click on a part it also generates parts in a random location where you have clicked and it explodes the parts.
Video:
As you can see the glitch is preventing me from making new holes also there is z-fighting