Attempt to connect failed: Passed value is not a function

-- 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(function() Callback:InvokeServer() end)
end
-- Client script

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)
-- Server script

function Callback.OnServerInvoke(Player)
    print("It worked")
end

AnimationRemote:FireClient(Player, "Reversal Red", "MarkerReached", "fire", Callback)

Thank you bro, it finally worked, but what should I do if I need different function for every marker and different skill, i canā€™t just go on making different remotes? Also sry for making u code everything.

Np, Iā€™m glad to help you :smiley:
No, the only solution is to create different remotes. But you can make a ā€œmacroā€:

function remote(callback)
    remoteFunction = Instance.new("RemoteFunction")
    function remoteFunction.OnServerInvoke(player)
        callback()
    end
    remoteFunction.Parent = ReplicatedStorage
    return remoteFunction
end

-- usage
event:FireClient(player, data1, data2, remote(function()
    print("action1")
end))
event:FireClient(player, data3, data4, remote(function()
    print("action2")
end))

Yo, on youtube i found someone who has a similar framework as me.
He did this on the serverhandler script:

rp.Server.OnServerInvoke = function(player,Cparams)
	
	local char = player.Character
	local root = char:WaitForChild("HumanoidRootPart")
	local hum = char:WaitForChild("Humanoid")
	local params = {
		player = player,
		root = root,
		hum = hum,
	}
	require(script[Cparams.Name.."Server"])[Cparams.Function](params, Cparams)
end

And this on a localscript:

rp.Server:InvokeServer({Name = "ExampleScript", Function = "ExampleFunction"})

Wouldnā€™t something like this also work?

Yes, it would. There are many ways to do this.

And what would be the best way to do it?

I donā€™t know. You can try different methods and find out by yourself.

Ok, tho thereā€™s one last thing I would like to ask you , all the abilities are stored in module scripts, so how I ā€œsendā€ the ā€œremoteā€ function to a modulescript?

wdym???

So this has to be on the server script right?
But this need to be in a module script:

event:FireClient(player, data1, data2, remote(function()
    print("action1")
end))
event:FireClient(player, data3, data4, remote(function()
    print("action2")
end))

Is it not possible?

Also, why does the animation manager module script use remotes, wouldnā€™t it just be better to require the module script instead?

It is possible. You just move this into a module script.

I donā€™t knowā€¦ You made this system.

Sadly, I didnā€™t. Donā€™t you think i would be able to fix the issue on my own?

Yes, however I donā€™t see any issues with this solution.

itā€™s finally working, i can continue making my game, and thanks to you I learned a lot about remotes. TYSM!!!

1 Like

Also thank you, for tying to help me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.