Hello I want an NPC to play walk cycle animation. The Animation does not play, The Animation is played on a script and is server-sided.
I have tried to set Network Ownership of all the NPCs parts to the server but that does not work too.
local walkAnimationTrack = human:LoadAnimation(script.Parent.WalkAnimation)
walkAnimationTrack.Priority = Enum.AnimationPriority.Action
walkAnimationTrack:Play()
Is this animation built for the correct rig type? For instance, if your NPCs are R15, have you ensured that the animation is built to play on an R15 character?
There are no output errors.
Here is the entire script, it is supposed to make the NPC move to the player when the player is not looking at it via a Remote event.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local CantSee = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
CantSee.OnServerEvent:Connect(function(player, NPC)
if not player.HunterFolder:FindFirstChild("Hunter1") then
local HunterFolder = player.HunterFolder
local Hunter = Instance.new("StringValue", HunterFolder)
Hunter.Name = "Hunter1"
Hunter.Value = game.Workspace.NPC.Name
end
NPC.HumanoidRootPart.Anchored = false
for _, part in pairs(NPC:GetDescendants()) do
if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
part:SetNetworkOwner(nil)
end
end
NPC.Binded.Value = true
local PathFindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("UpperTorso")
torso.Anchored = false
local char = player.Character or player.CharacterAdded:wait()
player.TargetedFolder.TargetedbyNPC1.Value = true
local walkAnimationTrack = human:LoadAnimation(script.Parent.WalkAnimation)
walkAnimationTrack.Priority = Enum.AnimationPriority.Action
walkAnimationTrack:Play()
while player.TargetedFolder.TargetedbyNPC1.Value == true do
local PathfindingService = game:GetService("PathfindingService")
local RunService = game:GetService('RunService')
local NPC = script.Parent
local Humanoid = NPC.Humanoid
local Destination = char.HumanoidRootPart.Position
local Path = PathFindingService:CreatePath({AgentHeight = 7, AgentRadius = 4, AgentCanJump = false, WaypointSpacing = 1})
local success, errorMessage = pcall(function()
Path:ComputeAsync(torso.Position, char.HumanoidRootPart.Position)
end)
if success and Path.Status == Enum.PathStatus.Success then
local activeCoroutine = nil
local follow=true
local update
local followPath
-- Loop update
coroutine.wrap(function()
while (follow) and player.TargetedFolder.TargetedbyNPC1.Value == true do
wait(1/3)
update()
end
end)()
function update()
Path:ComputeAsync(torso.Position, char.HumanoidRootPart.Position)
local Waypoints = Path:GetWaypoints()
table.remove(Waypoints, 1) -- First waypoint seems to always be origin
coroutine.wrap(followPath)(Waypoints) -- Follow new path
end
function followPath(waypoints)
activeCoroutine = coroutine.running()
for _, point in ipairs(waypoints) do
if activeCoroutine~=coroutine.running() then
return end -- No longer active path
Humanoid:MoveTo(point.Position)
Humanoid.MoveToFinished:Wait()
end
end
wait()
end
end
wait()
end)
I played around with the script and was able to get a dummy animation to play properly by setting its priority to Action in the animation editor rather than using a line of code to set the priority.
Essentially, delete this line
and instead set the animation priority to Action using the animation editor settings.
I did that but it still did not work. I opened the animation and set priority to Action then published it and used the new ID given. Or do I do something with this: