-
What do you want to achieve?
An AI that walks to the right Places, And doesn’t teleport. -
What is the issue?
The AI Should sit on the couch, After the HumanoidRootPart gets Teleported to the Position.
But the AI should walk to the position first, which doesn’t work Even though there’s an Wait with the WalkTo() Function. Also There’s no Error in the Output.
I Also have another Issue where the AI Doesn’t Do the Patrol() Function. Just stays in Place.
Here’s Footage of the AI Teleporting to the Place:
Here’s the AI Code:
local teddy = script.Parent
local humanoid = teddy.Humanoid
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
for i, player in ipairs(game.Players:GetPlayers()) do
script.Parent.HumanoidRootPart:SetNetworkOwner(player)
end
local PathfindingService = game:GetService("PathfindingService")
local function getPath(destination)
local pathParams = {
["AgentHeight"] = 5.6,
["AgentRadius"] = 1.1,
["AgentCanJump"] = false,
["WaypointSpacing"] = 1,
["AgentCanClimb"] = false,
}
for _, part in pairs(script.Parent:GetChildren()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
local path = PathfindingService:CreatePath(pathParams)
local waypointss = path:GetWaypoints()
--
path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
path.Blocked:Connect(function()
print("Path is blocked, Generating new Path..")
path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
end)
--
for _, part in pairs(script.Parent:GetChildren()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
return path
end
local function walkTo(destination)
local path = getPath(destination)
for _, part in pairs(script.Parent:GetChildren()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
for index, waypoint in pairs(path:GetWaypoints()) do
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
local function patrol()
for _, part in pairs(script.Parent:GetChildren()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
local waypoints = workspace.AIScripting.WayPoints:GetChildren()
local randomNum = math.random(1, #waypoints)
walkTo(waypoints[randomNum])
end
local AiFolder = game.Workspace.AIScripting
local Torso = script.Parent:WaitForChild("LowerTorso")
local HumPart = script.Parent:WaitForChild("HumanoidRootPart")
local Sounds = script.Parent.UpperTorso.SOUNDS
local Actions = AiFolder.Actions
local RandomActions = AiFolder.Actions.Random
while wait(1) do
function RandomizeAction()
local Randomizer = math.random(1,4) -- Last Number is the Maximum Actions Included.
if Randomizer == 1 then -- Just Walk Through the House.
patrol()
end
if Randomizer == 2 then --TV!!!
local AnimsActionTV = Actions.TV.Anims
walkTo(Actions.TV.Spawn)
HumPart.CFrame = Actions.TV.Spawn.CFrame
HumPart.Anchored = true
local Anim = humanoid:LoadAnimation(AnimsActionTV.Animation)
Anim:Play()
wait(0.5)
AnimsActionTV.Parent.Screen.SurfaceGui["Red Vs Blue Hammer Cartoon"].Visible = true
AnimsActionTV.Parent.Screen.SurfaceGui["Red Vs Blue Hammer Cartoon"].Playing = true
wait(20)
AnimsActionTV.Parent.Screen.SurfaceGui["Red Vs Blue Hammer Cartoon"].Visible = false
AnimsActionTV.Parent.Screen.SurfaceGui["Red Vs Blue Hammer Cartoon"].Playing = false
Anim:Stop()
HumPart.Anchored = false
end
if Randomizer == 3 then --Think
patrol() --make him Patrol before the Animation Plays.
local LoadThink = humanoid:LoadAnimation(RandomActions.Anims.Think)
LoadThink:Play()
wait(5)
LoadThink:Stop()
end
if Randomizer == 4 then --LookAround
patrol()
local LoadLook = humanoid:LoadAnimation(RandomActions.Anims.LookAround)
LoadLook:Play()
wait(2)
LoadLook:Stop()
end
end
-- Do the Function
RandomizeAction()
end
The Randomize function Near the end - “if randomizer == 2”
That’s where it teleports.
And yes I was using the Teddy Thing by GnomeCode as BaseCode.