Hi Devs. I’ve recently been experimenting with making animations that involve the actual player and I came across a bug I can’t seem to fix.
Whenever I step into the part it’s supposed to play an animation on the player and on the rig. but it only really plays it on the rig.
Here is my script I’ve tried (Yes I know I need to set the cframe of the player but I was going to do that later.)
local activationpart = game.Workspace.TouchPart
activationpart.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
local npc = game.Workspace.Rig
local npchum = npc:FindFirstChild("Humanoid")
local anim1 = hum:LoadAnimation(game.ServerStorage.Exports.PlayerSweep)
local anim2 = npchum:LoadAnimation(game.ServerStorage.Exports.NpcSweep)
anim1:Play()
anim2:Play()
end
end)
I’m following this tutorial
How to animate 2 characters and play it in-game like a takedown animation
But I’m also on the older version of moon animator.
(Don’t know if that helps but whatever)
Thanks!!!
1 Like
local activationPart = game.Workspace.TouchPart
local npc = game.Workspace.Rig
local playerSweepAnimation = game.ServerStorage.Exports.PlayerSweep
local npcSweepAnimation = game.ServerStorage.Exports.NpcSweep
activationPart.Touched:Connect(function(hit)
if not (hit.Parent and hit.Parent:FindFirstChild("Humanoid")) then return end
local character = hit.Parent
local humanoid: Humanoid = character:FindFirstChild("Humanoid")
local playerAnimator: Animator = humanoid.Animator
local npcHumanoid: Humanoid = npc:FindFirstChild("Humanoid")
if not npcHumanoid then return end
local npcAnimator: Animator = npcHumanoid:FindFirstChildOfClass("Animator")
if not npcAnimator then npcAnimator = Instance.new("Animator", npcHumanoid) end
playerAnimator:LoadAnimation(playerSweepAnimation):Play()
npcAnimator:LoadAnimation(npcSweepAnimation):Play()
end)
I just says Attempt to index nil with ‘animator’
here: local playerAnimator: Animator = humanoid.Animator
?
Yes that is where im getting the error message
What did you set as the animation priority in these animations?
First, I would recommend you load animations and storing them in a table when character loads, so you don’t have any delays when you need to play an animation.
here’s an example:
local LoadedAnimations = {}
local Animations = replicatedstorage.Animations -- folder with animation instances
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
for AnimationName, AnimationTrack in LoadedAnimations do
AnimationTrack:Destroy()
LoadedAnimations[AnimationName] = nil
end
for _, Animation in Animations:GetChildren() do
if Animation:IsA("Animation") then
LoadedAnimations[Animation.Name] = Animator:LoadAnimation(Animation)
end
end
end)
end)
Then you should just fire the client or use bindable events to run animations with
LoadedAnimations[AnimationName]:Play()
Or, you could make a module which would let you quickly access player’s animations, but its a bit different.
also, you can do the same for the NPCs.
figured it out by myself! I had an r6 animation but wasn’t on r6 