Idle Anim from replicatedstorage not going on npc

Hey everyone, im current;y trying to make it so that noob npcs that spawns from replicatedstorage to workspace have an idle animation, but its just not working and the animation isnt working. It should be working, since when i put the bignoob in workspace it works fine and the animations is there.

image

I can show ingame if needed!

Can you send that script? I see you don’t have an Animator under the humanoid, you need one.

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://some_id_here"

local track = Animator:LoadAnimation(anim)
track:Play()

this is the script:

it works when i directly put the noob in the workspace though, the animation is there

(I think you should still try with an animator, it might work)

Maybe try waiting until the model is in the workspace before playing the animation.

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
    if script.Parent.Parent == workspace then
        --play animation
    end
end)

Check if the animation exists before attempting to load and play it. If the animation is found, it loads it onto the humanoid and plays it use print statements

Or just try using this method as @12345koip suggests, this way, whenever the NPC is moved to the workspace the animation will play automatically

So the script would look like this:

local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild("Humanoid")

local idle = humanoid:LoadAnimation(animation)

local function CheckParent(parent)
    if parent == game.Workspace then
        idle:Play()
    end
end

-- Connect a function to Parent property changes
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
    CheckParent(script.Parent.Parent)
end)

CheckParent(script.Parent.Parent)

I mean, technically in my script the npc doesnt really spawn in the workspace, it spawns under certain folders, how would i do it instead?

image

Then you will have to create a variable for your specified Folder for example if you want to Parent it to “DesertBreakables” then it would look like this

local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild("Humanoid")
local destination = game.Workspace.Breakables.DesertBreakables -- change this to Folder location  where the NPC will spawn at

local idle = humanoid:LoadAnimation(animation)

local function CheckParent(parent)
    if parent == destination then -- check if the NPC got parented to your Folder
        idle:Play()
    end
end

-- Connect a function to Parent property changes
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
    CheckParent(script.Parent.Parent)
end)

CheckParent(script.Parent.Parent)

It might be easier to do something like this:

Rig:GetPropertyChangedSignal("Parent"):Connect(function()
    if rig:IsDescendantOf(workspace) then
        idle:Play()
    end
end)