I am trying to make a teleport attack move where once I click on the target, the target cant move and plays a animation where they turn around, problem is that the animation wont play
Local Script
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
script.Parent.Activated:Connect(function()
if not Mouse.Target then return end
if Mouse.Target.Parent:FindFirstChildOfClass("Humanoid") then
script.Parent.RemoteEvent:FireServer(Mouse.Target.Parent)
end
end)
Server Script
local Remote = script.Parent:WaitForChild("RemoteEvent")
Remote.OnServerEvent:Connect(function(Player, Target)
--TeleportBehindEnemy
local PlayerHumanoid = Player.Character:WaitForChild("HumanoidRootPart")
local TargetHumanoid = Target:WaitForChild("HumanoidRootPart")
local LastTargetPosition = TargetHumanoid.CFrame
local Length = -3 -- Length between player and target player
PlayerHumanoid.CFrame = LastTargetPosition + LastTargetPosition.LookVector * Length
PlayerHumanoid.CFrame = CFrame.new(PlayerHumanoid.CFrame.Position, Vector3.new(LastTargetPosition.Position.X, PlayerHumanoid.CFrame.Position.Y, LastTargetPosition.Position.Z))
--Freeze Enemy
local Position = Instance.new("BodyVelocity", TargetHumanoid)
Position.MaxForce = Vector3.new(99999999,9999999,9999999)
Position.P = 300
Position.Velocity = TargetHumanoid.CFrame.LookVector * .00001
--Enemy plays animation
local Anim = Instance.new("Animation")
local Animator = TargetHumanoid:FindFirstChild("Animator")
Anim.AnimationId = "rbxassetid://8649686359"
local Animation = Animator:LoadAnimation(Anim)
Animation:Play()
end)
If someone could explain why my animation isn’t playing I would appreciate it
Hmm, could it be you left the animation’s priority to “Core”? Make sure it’s set to “Action”. If you prefer doing it through code (and maybe save some time), you can change the property directly from the AnimationTrack.
-put a print to make sure it reaches that part of the code,
-try changing the anim’s parent to animator,
-and instead of animator just load it on the humanoid.
i dont know if this will fix the problem but its worth a try i guess
I’ve never used Humanoid.Animator, have you tried using Humanoid:LoadAnimation()?
And please use Local scripts for animations because animations on server will be delayed or slower than the animation on the client.
You were attempting to find an “Animator” instance inside the “HumanoidRootPart” BasePart instance of the player’s/NPC’s character, even though the “Animator” instance is parented to the “Humanoid” instance.
local Animation = Animator:LoadAnimation(Anim)
This line would’ve thrown/raised an error like “Attempt to index nil with LoadAnimation” followed by some information regarding the error.