I made a script for a SCP-096 model that tracks targets, and i found this issue:
The 096 finds the target but bumps into a wall and gets stuck. I have tried removing a portion of the code that my friend told me to, it works, but the character “lags” and teleports instead of moving smoothly. I have even tried setting the network ownership of the primary part to the server but to no avail.
One thing i also have to mention is that i have added a PathFindingModifier in the door and set the PassThrough bool to true and made a system where the doors gets destroyed if touched.
With the complete code:
Without the part i removed:
The code (simplified):
script.Parent.PrimaryPart:SetOwnership(nil)
local path = pathfindingservice:CreatePath()
local waypoints, nextwaypoint
--local reachedconnection
local function followpath(targetpos)
local sucess = pcall(function()
path:ComputeAsync(script.Parent.PrimaryPart.Position,targetpos)
end)
if sucess then
waypoints = path:GetWaypoints()
if #waypoints == 0 then return end
--[[ removed part below
if not reachedconnection then
reachedconnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextwaypoint < #waypoints then
nextwaypoint += 1
humanoid:MoveTo(waypoints[nextwaypoint].Position)
end
end)
nextwaypoint = 2
humanoid:MoveTo(waypoints[nextwaypoint].Position)
end]] -- removed part above
nextwaypoint = 2
humanoid:MoveTo(waypoints[nextwaypoint].Position)
end
end
while wait(.5) do
followpath(findnearesttarget().PrimaryPart.Position)
end