i have an npc which shoots a part (lazer) at the player, however when the part gets shot the npc just breaks (stops moving and infinitely jumping)
it is only the park breaking the npc, as if i dont set the parent it doesnt break but the lazer isnt there
code to shoot lazer:
local ShockClone = ShockPart:Clone()
ShockClone.Anchored = true
ShockClone.CanCollide = false
ShockClone.CanQuery = false
ShockClone.Massless = true
ShockClone.Parent = biglenny
for i, v in ipairs(ShockClone:GetChildren()) do
if v:IsA("ParticleEmitter") or v:IsA("PointLight") then
v.Enabled = true
end
end
local startPosition = humanoidrootpart.Position
local laserDistance = (startPosition - hitPosition).Magnitude
local shockcframe = CFrame.lookAt(startPosition, hitPosition) * CFrame.new(0, 0, -laserDistance / 2)
ShockClone.CFrame = humanoidrootpart.CFrame
ShockClone.Transparency = 0
local FireLazerT = tweenserv:Create(ShockClone, TweenInfo.new(lazerSpeed), {CFrame = CFrame.new(hitPosition)})
FireLazerT:Play()
ShockClone.Touched:Connect(function(partTouched)
if partTouched.Parent:FindFirstChild("Humanoid") and not partTouched.Parent:IsDescendantOf(biglenny) then
print('hit player zap')
partTouched.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
FireLazerT.Completed:Wait()
ShockClone:Destroy()
I think the issue is with the “touched” event of the “ShockClone”. The NPC might be breaking cause the event is executing an action that is too uhh time-intensive. So you could try adding a delay before executing the action, so that it doesn’t happen too quickly.
What is the NPC’s code? Are you using PathfindingService to map paths for the NPC to move along? What is prompting you to recalculate the navigation mesh for the NPC? It sounds like the lazer’s part spawning is causing the NPC’s path to get blocked, and it’s getting stuck in a loop because it has no viable path.
Can you try adding some print statements to your NPC’s code to find the hang-up? It may also be helpful if you send a video of what’s happening with the NPC.
It may be helpful for me to see more code. You don’t necessarily need to send me everything, but if I could see some more of the NPC code I may be better able to deduce the issue.