Attempt to connect failed: Passed value is not a function

So, I have a custom animation manager module that helps in using animations more efficiently. But recently, I wanted to add a new function that I really need for my game, but this error keeps coming up. Idk how to fix it cuz it’s not even my animation manager. Does anyone know what I should do?

The function from the module script:

function AnimationHandler.MarkerReached(AnimationName, AnimationData, Callback)
	
	AnimationName = (typeof(AnimationName) == "string" and AnimationName) or warn(INVALID_ANIMATION_ERROR)
	if not AnimationHandler[Character.Name].LoadedAnimations[AnimationName] then return end
	
	local Track = AnimationHandler[Character.Name].LoadedAnimations[AnimationName]
	Track:GetMarkerReachedSignal(AnimationData):Connect(Callback)
end

Then I use my ClientHandler LocalScript:

local AnimationSettings = {
	["Play"] = function(AnimationName, AnimationData)
		AnimationManager.PlayAnimation(AnimationName, AnimationData)
	end,
	["MarkerReached"] = function(AnimationName, AnimationData, Callback)
		AnimationManager.MarkerReached(AnimationName, AnimationData, Callback)
	end,
	["Stop"] = function(AnimationName, AnimationData)
		AnimationManager.StopAnimation(AnimationName, AnimationData)
	end,
	["LoadAnimations"] = function(Character, ClassNames)
		AnimationManager.LoadAnimations(Character, ClassNames)
	end,
}

AnimationRemote.OnClientEvent:Connect(function(AnimationName,Task,AnimationData,Callback)
	AnimationSettings[Task](AnimationName,AnimationData,Callback)
end)

And then I fire the remoteevent when needed:

AnimationRemote:FireClient(Player, "Reversal Red", "MarkerReached", "fire", function()
	print("It worked")
end)

The error I get in output window:

Attempt to connect failed: Passed value is not a function  -  Studio
Stack Begin  -  Studio
Script 'ReplicatedStorage.Modules.Shared.AnimationManager', Line 109 - function MarkerReached  -  Studio - AnimationManager:109
Script 'Players.SussyZets.PlayerScripts.Client.Core', Line 59  -  Studio - Core:59
Script 'Players.SussyZets.PlayerScripts.Client.Core', Line 113  -  Studio - Core:113
Stack End

Any help would be really appreciated.

3 Likes

maybe make it so that the function is predefined so

local function Test()
 print("Hi")
end

AnimationRemote:FireClient(Player, "Reversal Red", "MarkerReached", "fire", Test())
1 Like

This sounded very smart, but sadly it didn’t work :sob:

3 Likes

Can I see the :GetMarkerReachedSignal script? And to debug it just print out the typeof of the Connection value passed when you call the function

2 Likes

Do u mean the full module script

--|| Services ||--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local TaskScheduler = {}
local Cache = {}
local SteppedConnection = nil

--|| Modules ||--
local Utility = require(ReplicatedStorage.Modules.Utility.Utility)

--|| Folders ||--
local AnimationFolder = ReplicatedStorage.Assets.Animations

--|| Remotes ||--
local AnimationRemote = ReplicatedStorage.Remotes.AnimationRemote

--|| Module ||--
local AnimationHandler = {
	Characters = {},

	QueuedList = {"Pain"}
}

--|| Variables ||--
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local INVALID_ANIMATION_ERROR = "Requested Animation is an invalid type"

function AnimationHandler.CreateProfile(Character)
	local Profile = AnimationHandler[Character.Name]

	if Profile == true then return end

	AnimationHandler[Character.Name] = {
		LoadedAnimations = {}
	}
end

function AnimationHandler:GetProfile(Character)
	if AnimationHandler[Character.Name] == true then
		return true, AnimationHandler[Character.Name]
	else
		AnimationHandler.CreateProfile(Character)
		return true, AnimationHandler[Character.Name]
	end

end

function AnimationHandler.LoadAnimations(Character,ClassNames)
	local _,Profile = AnimationHandler:GetProfile(Character)
	ClassNames = (typeof(ClassNames) == "string" and {ClassNames}) or ClassNames

	local Humanoid = Character:WaitForChild("Humanoid")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")

	for _,ClassName in ipairs(ClassNames) do
		local SharedAnimations = AnimationFolder.Shared

		local CachedShared = Utility:deepSearchFolder(SharedAnimations,"Animation")

		for _,Animation in ipairs(CachedShared) do
			if AnimationHandler[Character.Name].LoadedAnimations[Animation.Name] then continue end
			AnimationHandler[Character.Name].LoadedAnimations[Animation.Name] = Animator:LoadAnimation(Animation)			
		end
	end
end

function AnimationHandler.PlayAnimation(AnimationName,AnimationData)
	AnimationName = (typeof(AnimationName) == "string" and AnimationName) or warn(INVALID_ANIMATION_ERROR)
	if not AnimationHandler[Character.Name].LoadedAnimations[AnimationName] then warn(AnimationName,"is not a valid animation") return end

	local FadeTime = AnimationData and AnimationData.FadeTime or .1
	local Weight =  AnimationData and AnimationData.Weight or 1
	local AdjustSpeed = AnimationData and AnimationData.AdjustSpeed or 1
	local Looped = AnimationData and AnimationData.Looped or false

	local Track = AnimationHandler[Character.Name].LoadedAnimations[AnimationName]
	Track:Play(FadeTime,Weight)
	Track:AdjustSpeed(AdjustSpeed)

	Track.Looped = Looped
end

function AnimationHandler.MarkerReached(AnimationName, AnimationData, Callback)
	
	AnimationName = (typeof(AnimationName) == "string" and AnimationName) or warn(INVALID_ANIMATION_ERROR)
	if not AnimationHandler[Character.Name].LoadedAnimations[AnimationName] then return end
	
	local Track = AnimationHandler[Character.Name].LoadedAnimations[AnimationName]
	Track:GetMarkerReachedSignal(AnimationData):Connect(Callback)
end

function AnimationHandler.StopAnimation(AnimationName,AnimationData)
	AnimationName = (typeof(AnimationName) == "string" and AnimationName) or warn(INVALID_ANIMATION_ERROR)
	if not AnimationHandler[Character.Name].LoadedAnimations[AnimationName] then return end

	local FadeTime = AnimationData and AnimationData.FadeTime or .1
	local Weight = AnimationData and AnimationData.Weight or 1

	local Track = AnimationHandler[Character.Name].LoadedAnimations[AnimationName]
	Track:Stop(FadeTime,Weight)
end

function AnimationHandler.AddQueue(AnimationStyle)
	AnimationStyle = (typeof(AnimationStyle) == "string" and AnimationStyle) or warn(INVALID_ANIMATION_ERROR)

	for _,QueuedStyle in ipairs(AnimationHandler.QueuedList) do
		if QueuedStyle == AnimationStyle then
			return
		end
	end
	AnimationHandler.QueuedList[#AnimationHandler.QueuedList + 1] = AnimationStyle
end

function AnimationHandler.RemoveQueue(AnimationStyle)
	AnimationStyle = (typeof(AnimationStyle) == "string" and AnimationStyle) or warn(INVALID_ANIMATION_ERROR)

	for _,QueuedStyle in ipairs(AnimationHandler.QueuedList) do
		if QueuedStyle == AnimationStyle then
			AnimationHandler.QueuedList[QueuedStyle] = nil
		end
	end
end

function AnimationHandler.ClearAnimations(Character)
	local HasProfile,Profile = AnimationHandler:GetProfile(Character)
	if HasProfile == nil then return end

	for AnimationName, _ in ipairs(AnimationHandler.LoadedAnimations) do
		Profile.LoadedAnimations[AnimationName] = nil
	end
end

spawn(function()
	AnimationHandler.CreateProfile(Character)
	AnimationHandler.LoadAnimations(Character,AnimationHandler.QueuedList)
end)

Player.CharacterAdded:Connect(function(NewCharacter)

	Character = NewCharacter

	AnimationHandler.CreateProfile(NewCharacter)

	AnimationHandler.LoadAnimations(Character,AnimationHandler.QueuedList)
end)

Player.CharacterRemoving:Connect(function(Character)
	AnimationHandler.ClearAnimations(Character)
end)

return AnimationHandler 

There’s a bunch of things tho

2 Likes

Where does that function come from? It isn’t in the module script

1 Like
3 Likes

Ok so in the Marker Reached function just add in print(typeof(Callback)) then that will tell you if it is a function or something else

2 Likes

Still got the error, maybe it’s something related to the localscript

2 Likes

what did that print out that will tell you what it is?

2 Likes

ow sry, i didn’t notice it prints out “nil”

2 Likes

so that saying the function doesn’t exist

1 Like

Also I just noticed that even tho there is the error, “Hi” gets printed anyway. How?

2 Likes

Maybe wrap it in a pcall then just see if it works with other functions?

2 Likes

Sry but i am not an experienced scripter, i don’t know how to do that

2 Likes

It’s ok. So pcall basically just catch errors and stop them from stopping the code

so instead of doing Track:GetMarkerReachedSignal(AnimationData):Connect(Callback)

you can do

pcall(function()
Track:GetMarkerReachedSignal(AnimationData):Connect(Callback)
end)
1 Like

Didn’t work. Maybe the error is because I use a RemoteEvent?

2 Likes

It shouldn’t error. Pcalls block any error caused by anything inside it from printing

2 Likes

But it does print the error, how???

2 Likes

I don’t know. I have to go now so won’t be able to help sorry.

1 Like