Attempt to connect failed: Passed value is not a function

You can’t pass functions as arguments to remote events & functions.

2 Likes

Before you go, I wrapped the [“markerreached”] and animation remote in a pcall, the error stopped appearing, and the error stopped but now the function just fire immediately

1 Like

Oh, I actually thought about that, but if doing so is not possible, do you know any other way I could do it?

Yes. You could pass a RemoteFunction as a callback. But notice that it must be created on the server.

So instead of using a remoteevent i should use a remotefunction? and what do you mean by “it must be created on the server”?

1 Like

No, you can still use RemoteEvent. But instead of passing lua function you can pass RemoteFunction

1 Like

Uhm, sorry but could you give me an example of how i would do it, im new to scripting and i struggle so much with remotes, arguments and all that hard stuff :sweat_smile:

I tried to do it myself but still got the error, what I did was create a new remotefunction, then i made a new function in my localscript, and then instead of doing “animationremote:FireClient” i did “animationfunction:InvokeClient”

the local script function:

local function Animation(AnimationName,Task,AnimationData,Callback)
	AnimationSettings[Task](AnimationName,AnimationData,Callback)
end

AnimationFunction.OnClientInvoke = Animation

The InvokeClient thing:

		AnimationFunction:InvokeClient(Player, "Reversal Red", "MarkerReached", "ready", function()
			print("Worked?")
		end)

No, do not use lua function as callback. Use RemoteFunction instead.

-- callback is a RemoteFunction

function callback.OnServerInvoke()
    print("Hello world")
end

event:FireClient(1, 2, 3, callback)

You can’t send functions over remote events. It converts to just a string.

Oh,got the same error, these remotes thing is really hard.

I did this on a module script (and i think that’s why it doesn’t work)

		function Callback.OnServerInvoke()
			print("YEEEES")
		end
		
		AnimationRemote:FireClient(Player, "Reversal Red", "Play")
		AnimationRemote:FireClient(Player, "Reversal Red", "MarkerReached", "ready", Callback)

So you said it should be created on the server, but what do i do if i have multiple markers and everyone of them needs different functions, i can’t just keep making new remotefunctions everytime.

And even after putting this in a server script:

function Callback.OnServerInvoke()
	print("YEEEES")
end

And this in the module script:

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

It didn’t work. Ohh, I am so tired of this it’s been like 5 days that i am trying to figure this out. Thank to everyone for their help so far.

1 Like

What exactly didn’t work? Did you get any errors?

Got the same error

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

It’s because you can’t connect RemoteFunction to an event. You must create a wrapper:

event:Connect(function() callback:InvokeServer() end)

I did this:

AnimationRemote:Connect(Player, "Reversal Red", "MarkerReached", "ready", function() Callback:InvokeServer() end)

And I get this error:

Connect is not a valid member of RemoteEvent "ReplicatedStorage.Remotes.AnimationRemote"  -  Server - Gojo:436
Stack Begin  -  Studio
Script 'ServerScriptService.Server.Characters.Gojo', Line 436  -  Studio - Gojo:436
Script 'ServerScriptService.Server', Line 218  -  Studio - Server:218
Stack End

I also did

AnimationRemote.OnServerEvent:Connect(Player, "Reversal Red", "MarkerReached", "ready", function() Callback:InvokeServer() end)

But I still get the same error.

No! You CANNOT pass Lua functions to remotes. You must create wrapper when you connect roblox event, not when you invoke RemoteFunction.