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