So, I followed the teddy AI tutorial. The AI works as intended, however when in the roblox player the walking animation like stutters and it looks like the model keeps tripping. And sometimes the animation doesn’t play at all. I’m not sure why this is happening, please help. Maybe it’s happening because its multiplayer and it’s not running on the client fps? Even so I don’t know how I would incorporate this into a script.
If you would like an rbxm of the model i will send.
Here is the AI script
local teddy = script.Parent
local humanoid = teddy.Humanoid
teddy.PrimaryPart:SetNetworkOwner(nil)
local function canSeeTarget(target)
local origin = teddy.HumanoidRootPart.Position
local direction = (target.HumanoidRootPart.Position - teddy.HumanoidRootPart.Position).unit * 55
local ray = Ray.new(origin, direction)
local hit, pos = workspace:FindPartOnRay(ray, teddy)
if hit then
if hit:IsDescendantOf(target) then
return true
end
else
return false
end
end
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = 55
local nearestTarget
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance and canSeeTarget(target) then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function jumpscare(target)
local remote = game.ReplicatedStorage.JesterJS
remote:FireClient(target)
end
local function getPath(destination)
local PathfindingService = game:GetService("PathfindingService")
local pathParams = {
["AgentHeight"] = 12,
["AgentRadius"] = 4,
["AgentCanJump"] = false
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
return path
end
local function attack(target)
local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
local plr = target
if distance > 5 then
humanoid:MoveTo(target.HumanoidRootPart.Position)
teddy.Humanoid.WalkSpeed = 18
teddy.JumpscareTouch.Running.PlaybackSpeed = 0.684
else
local attackAnim = humanoid:LoadAnimation(script.Attack)
attackAnim:Play()
target.Humanoid.Health = 0
end
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
local target = findTarget()
if target and target.Humanoid.Health > 0 then
print("TARGET FOUND", target.Name)
attack(target)
break
else
teddy.Humanoid.WalkSpeed = 16
teddy.JumpscareTouch.Running.PlaybackSpeed = 0.634
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
else
humanoid:MoveTo(destination.Position - (teddy.HumanoidRootPart.CFrame.LookVector * 20))
end
end
function patrol()
local waypoints = workspace.waypoints
--local randomNum = math.random(1, #waypoints)
walkTo(waypoints["1"])
walkTo(waypoints["5"])
walkTo(waypoints["1"])
walkTo(waypoints["6"])
walkTo(waypoints["2"])
walkTo(waypoints["3"])
walkTo(waypoints["4"])
walkTo(waypoints["6"])
walkTo(waypoints["1"])
end
while wait(0) do
patrol()
end