I’m working on a hit effect, however I’m facing a bug which I unfortunately can’t figure out how to fix.
Below is a record of the glitch, as well as the script used.
local Parts = Mob:GetChildren()
local function WeldParts(Part0, Part1)
Part1.Anchored = false
local weld = Instance.new("ManualWeld")
weld.Part0 = Part0
weld.Part1 = Part1
weld.Parent = Part1
end
local function HitEffect()
for i, Part in pairs(Parts) do
if Part:IsA("MeshPart") then
local Outline = Part:Clone()
Outline.Name = "Outline"
Outline.CanCollide = false
Outline.Size = Part.Size + Vector3.new(0.3,0.3,0.3)
Outline.Material = Enum.Material.SmoothPlastic
Outline.Color = Color3.fromRGB(255, 0, 0)
Outline.Parent = Mob.HitEffect
Outline.CFrame = Part.CFrame
Outline.Transparency = 1
if Outline:IsA("MeshPart") then
Outline.TextureID = ""
end
WeldParts(Part, Outline)
Debris:AddItem(Outline, HitTime)
spawn(function()
local Part = Outline
local Initial = {} Initial.Transparency = 0
local Final = {} Final.Transparency = 1
local tweenInfo = TweenInfo.new(HitTime*1/10)
local Tween = TweenService:Create(Part, tweenInfo, Initial)
Tween:Play(); Tween.Completed:Wait(); wait(HitTime*2/10)
print(Part.Transparency)
tweenInfo = TweenInfo.new(HitTime*7/10)
Tween = TweenService:Create(Part, tweenInfo, Final)
Tween:Play()
wait(HitTime/1.66)
print(Part.Transparency)
end)
end
end
end
So the problem is that when you hit the mob, it’s moving when it shouldn’t? If so, could you just set the mob parts to canCollide = false? Or maybe create collision groups for the mob and the weapon so the weapon and mob parts don’t collide? That might stop it from moving when struck.
Sorry, I still don’t understand what the issue is I guess. Can you elaborate on exactly what you mean by “it glitches”. What exactly is happening that shouldn’t be?
The mob movement is not correct. When the humanoidrootpart is anchored, the mob is supposed to not move at all, however for some reason it does. That’s the problem.
Of course anchoring it was only to show the problem, there are random glitches when the mob is hit while moving as in the video provided.
My suggestion earlier though about setting the mob parts to canCollide=false should stop the weapon strike from affecting the part physics. You can still detect when the weapon touches the part even without collisions. I didn’t notice anything in the script that would affect the mob movement.
You’re anchoring the humanoidrootpart, however the animation can still play. Have you tried anchoring the whole mob?
Would you mind also providing what the mob is using to navigate itself? Also what method are you doing to make the mob knock back? I have a feeling the glitches lies within there.
FIXED: The problem was that :Clone() was cloning the instance children too, which included the joints of the Mob.
By simply using Outline:ClearAllChildren() it worked as intended.