I have a script that cuts parts in half and deletes the part that was cut in half but sometimes flickering happens when the cut part is being replaced I tried delaying the deletion time of the part that is getting cut in half and while the flickering did happen less it still happened and I don’t want it to be delayed too
Here is a video of this
Here is the code:
local function ClonePart(Part)
local New = Part:Clone()
New.Parent = Part.Parent
return New
end
function module.SplitPart(Part,axies)
local Part1 = ClonePart(Part)
local Part2 = ClonePart(Part)
local Default = Vector3.new(1,1,1)
Part1.Size = Part.Size * (-axies / 2 + Default)
Part1.CFrame = Part.CFrame * CFrame.new(-Part.Size * (Default * axies / 4))
Part2.Size = Part.Size * (-axies / 2 + Default)
Part2.CFrame = Part.CFrame * CFrame.new(Part.Size * (Default * axies / 4))
Part:Destroy()
end
this function is happening a couple of times until the desired part size is reached (I could provide code for that if needed)
Thanks to anyone who can help
Looking at the frame when it flickers, it seems that you either destroy the part’s being split a frame before creating new parts, or you don’t parent the new part’s instantly. As the code however doesn’t seem to show that that’s the case, can you show me the part of the code that calls module.SplitPart multiple times?
function module.MakePartsFall(HitBox,NetWorkOwner)
local Parts
local NewPart = HitBox:Clone()
local Hit = false
repeat
Parts = workspace:GetPartsInPart(NewPart)
for i,Part : Part in pairs(Parts) do
if IsPartSplitable(Part) then
if Part.Size.X > module.minBrickSize or Part.Size.Y > module.minBrickSize or Part.Size.Z > module.minBrickSize then
local Largest = GetLargestAxis(Part)
if Largest == Part.Size.X then
module.SplitPart(Part,Vector3.new(1,0,0))
elseif Largest == Part.Size.Y then
module.SplitPart(Part,Vector3.new(0,1,0))
elseif Largest == Part.Size.Z then
module.SplitPart(Part,Vector3.new(0,0,1))
end
elseif Part.Anchored then
Part.Anchored = false
table.insert(Ign,Part)
task.spawn(function()
Part:SetNetworkOwner(NetWorkOwner)
Respawn(Part,20)
Hit = true
Part.Size = Part.Size - Vector3.new(0.05,0.05,0.05)
local At = Instance.new("Attachment")
At.Parent = Part
local Velocity = Instance.new("LinearVelocity")
Velocity.MaxForce = 10000
Velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
Velocity.LineDirection = (-(HitBox.Position - Part.Position).Unit)
Velocity.LineVelocity = 10
Velocity.Attachment0 = At
Velocity.Parent = Part
task.delay(0.2,function()
Velocity.MaxForce = 0
Velocity.LineVelocity = 0
task.wait(1)
Velocity:Destroy()
At:Destroy()
end)
end)
end
else
Parts[i] = nil
end
end
until GetTotalValsInTab(Parts) == 0
if Hit then
local Rocks = ss.Sounds.Rocks:Clone()
NewPart.Transparency = 1
NewPart.Anchored = true
NewPart.CanCollide = false
NewPart.Parent = workspace
Rocks.Parent = NewPart
Rocks:Play()
end
end
I’m not entirely sure if this is a roblox bug or not, but you could try to add a 1 frame delay before destroying the part and see if that at least gets rid of the flicker. You can do that with something like this
task.spawn(function()
RunService.Heartbeat:Wait() -- You'll need to define RunService as game:GetService("RunService") too
Part:Destroy()
end)
I went through the part where the glass actually breaks frame-by-frame, and that flicker that we had before is no longer happening, however what is happening is near definitely a Roblox problem, because there is some lighting updating going on (pictures). You could try experimenting with changing RunService.Heartbeat to RunService.Stepped, but I doubt it’ll make a difference.