why does it jitter all like that (i use simplepath module)
pls awnser me, i have been searching for a solution last month and this month (fun fact it did not help at all)
pls. if additional info is needed please inform me of it… im legit so tired of this one thing its been bothering me since the start of time itself and i might not awnser immediately but please dont be hesitant to awnser i would literally accept any help just plzzzzz i hate this bug so muuuch
--((Services))
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService('Players')
local PathfindingService = game:GetService("PathfindingService")
--((Variables))
local SimplePath = require(ServerStorage.SimplePath)
local NPC = script.Parent
local Animator = NPC.Humanoid:FindFirstChild("Animator")
local Animation = ServerStorage.Anims.Attack
local AnimationLoaded = Animator:LoadAnimation(Animation)
local WooshSFX = NPC.HumanoidRootPart.Woosh
local Extraspeed = script.Parent:GetAttribute("AttackSlowdown")
--((Attack Function))
local function AttackFX()
WooshSFX:Play()
AnimationLoaded:Play()
end
for index, NPCpart in pairs(NPC:GetDescendants()) do
if NPCpart:IsA("MeshPart") or NPCpart:IsA("BasePart") then
NPCpart:SetNetworkOwner(nil)
end
end
local AgentParams = {
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = false,
WaypointSpacing = 4
}
--((StartAI Function))
local function StartAI()
local NearestPLR, NearestDist, NearestAttackDist, Damage = nil, nil, nil, nil
local path = SimplePath.new(NPC, AgentParams)
--((Path Variables))
path.Visualize = true
while wait() do
if NPC.Humanoid.Health > 0 then
NearestPLR, NearestDist, NearestAttackDist, Damage = nil, NPC:GetAttribute("SearchRange"), NPC:GetAttribute("AttackDistance"), NPC:GetAttribute("Damage")
for _, plr in ipairs(workspace:GetChildren()) do
if plr ~= nil then
if plr:FindFirstChild("IsPlayer") or plr:FindFirstChild("IsCore") then
local dist = (NPC.PrimaryPart.Position - plr.PrimaryPart.Position).Magnitude
if dist < NearestDist then
NearestPLR = plr
NearestDist = dist
if dist < NearestAttackDist then
AttackFX()
NPC.Humanoid.WalkSpeed = NPC.Humanoid.WalkSpeed - Extraspeed
task.wait(0.4)
local Coroutine = coroutine.wrap(function()
local dist2 = (NPC.PrimaryPart.Position - plr.PrimaryPart.Position).Magnitude
if dist2 < NearestAttackDist then
local hum = plr:FindFirstChild("Humanoid")
hum:TakeDamage(Damage)
end
NPC.Humanoid.WalkSpeed = NPC.Humanoid.WalkSpeed + Extraspeed
task.wait(1.5)
end)
Coroutine()
end
end
end
end
end
end
if NearestPLR ~= nil then
path.Blocked:Connect(function()
if NearestPLR then
SimplePath:Run(NearestPLR.PrimaryPart)
end
end)
path.WaypointReached:Connect(function()
if NearestPLR then
path:Run(NearestPLR.PrimaryPart.Position)
end
end)
if NearestPLR then
path:Run(NearestPLR.PrimaryPart.Position)
end
NPC.Humanoid.Died:Connect(function()
SimplePath:Stop()
end)
end
end
end
StartAI()