Script not returning anything - Animation

print("♻️ Loading " .. script.Name .. " : " .. script.ClassName .. " : " .. script.Parent.Name)
-- {{ VARIBLES }}
local M14Tool = script.Parent
local Humanoid = M14Tool.Parent.Parent.Character:WaitForChild("Humanoid")
local Animator = Humanoid.Animator
M14Tool.AnimHandle.Parent = Humanoid.Parent:WaitForChild("RightArm")
-- {{{ ANIMATION INSTANCE VARIBLES }}}
local BoltBackAnimation = script.BoltBack
local InspectionAnimation = script.Inspection
local PortArmsToPresentArmsL = script.PortArmsToPresentArmsL
local PortArmsToPresentArmsR = script.PortArmsToPresentArmsR
local PortArmsToAttentionL = script.PortArmsToPresentArmsL
local PortArmsToAttentionR = script.PortArmsToAttentionR
local PortArmsToLeft = script.PortArmsToLeft
local PortArmsToRight = script.PortArmsToRight
local RightHoldToPortAArms = script.RightHoldToPortArms
local LeftHoldToPortArms = script.LeftHoldToPortArms

-- {{{ CHECK VARIBLES }}}
local animationIsPlaying = false

-- {{ FUNCTIONS }}
local function playAnimation(animation)
	if animationIsPlaying then warn("Unable to play user animation for M14. User has animation ongoing") return end
	animationIsPlaying = true
	print("♻️ Playing animation")
	animation:Play()
	print("✅ Animation started")
	animation.Ended:Connect(function()
		animationIsPlaying = false
		print("✅ Animation Ended")
	end)
end

local function loadAnimation(animationInstance)
	print("♻️ Loading Animation : " .. animationID)
	return Animator:LoadAnimation(animationInstance)
end

local function setupAnimationVariables()
	print("♻️ Loading animations...")
	BoltBackAnimation = loadAnimation(BoltBackAnimation)
	print("🕛 Loaded Bolt Back")
	InspectionAnimation = loadAnimation(InspectionAnimation)
	print("🕛 Loaded Inspection")
	PortArmsToPresentArmsL = loadAnimation(PortArmsToPresentArmsL)
	print("🕛 Loaded Port to Present Left")
	PortArmsToPresentArmsR = loadAnimation(PortArmsToPresentArmsR)
	print("🕛 Loaded Port to Present Right")
	PortArmsToAttentionL = loadAnimation(PortArmsToAttentionL)
	print("🕛 Loaded Port to Attention Left")
	PortArmsToAttentionR = loadAnimation(PortArmsToAttentionR)
	print("🕛 Loaded Port to Attention Right")
	PortArmsToLeft = loadAnimation(PortArmsToLeft)
	print("🕛 Loaded Port to Left")
	PortArmsToRight = loadAnimation(PortArmsToRight)
	print("🕛 Loaded Port to Right")
	RightHoldToPortAArms = loadAnimation(RightHoldToPortAArms)
	print("🕛 Loaded Right to Port")
	LeftHoldToPortArms = loadAnimation(LeftHoldToPortArms)
	print("🕛 Loaded Left to Port")
	print("✅ Loaded animations!")
end
setupAnimationVariables()
M14Tool.Equipped:Connect(function()
	print("🎮 Tool : M14 : Equip Function Run")
	playAnimation(PortArmsToAttentionR)
	print("♻️ Animation started...")
	print("♻️ Waiting 5 and playing again")
	task.wait(5)
	playAnimation(PortArmsToAttentionR)
end)

image

The rest of the script is not running. I’m really inexpiereced in scripting with tools & animations, I mainly script UI. All help greatly appreciated.


Could it be that you accidentally toggled off one of these? It looks like there is an error, but something prevents it from showing.

image

Strange… :anguished:
Also, I think I see the issue!!!


An R6 character doesn’t have a “RightArm”, it’s called a “Right Arm”. Hence why it infinitely yields, awaiting for it. I don’t know why the output lacks the appropriate warning.

image

local function loadAnimation(animationID)
	print("♻️ Loading M14 Animation : " .. animationID.Name)
	return Animator:LoadAnimation(animationID)
end

Happening on the return line. The “animationID” is an instance btw ← changed to animation instances after, before i was using just ids

This happens because you load animations too early. The character is still in nil.

So player.Character:Wait()? Is it required that I run it locally? It’s currently running serverside.

local tool = script.Parent

local player = tool:FindFirstAncestorOfClass("Player")
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:Wait()
end

Maybe something like this would work…

And no, the script can be server-sided in this case.