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.
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)
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)