InvokeServer not returning required module

  1. What do you want to achieve?
    I want to get module required on server from client

  2. What is the issue?
    In the server script, it prints the module functions. However on the client, it prints nil

  3. What solutions have you tried so far?
    I tried searching on forum but didn’t find anything helpful.

Client:

local ragdmodule = evs.GetRagdollModule:InvokeServer()
print(ragdmodule.Ragdoll) --printing nil

Server:

--printing function name at the start
evs.GetRagdollModule.OnServerInvoke = function (p)
	return require(game.ReplicatedStorage.Modules.RagdollModule):init()
end

Module:

local module = {}
--some stuff
module.Ragdoll = function --some stuff

function module:init()
	return self
end

return module

Thank you for any help

1 Like

You can’t transfer metatables or functions over a remote/bindable instance. There’s a hacky way to do it by using table.pack though, so try that out. If you want I can send a basic Signal class that handles it for you.

i did exactly the same what I’m trying to achieve with other module and it works:

local module = {}
local evs = game.ReplicatedStorage.Events
function module.new(char: Model): Character
	if game["Run Service"]:IsServer() then
		local req = require(script.CharacterClass)
		return req:Init(char.Name)
	else
		return script.Parent.NewCharClassRemote:InvokeServer(char.Name)
	end
end
function module:GetClassOf(char: Model): Character
	if game["Run Service"]:IsServer() then
		return evs.GetCharClass:Invoke(char.Name) or module.new(char)
	else
		return evs.GetCharClassRemote:InvokeServer(char.Name) or module.new(char)
	end
end
local mt = {}
mt.__index = "CharacterModule"
setmetatable(module, mt)
return module
1 Like

If you have to use such a “hacky” ways, means you are doing your job wrong.
Is there a reason you hide from client that RagdollModule?

put your module somewhere that server and client can see.
Then require it on both sides.
You are overcomplicating stuff for no real reason.

I can’t require it on client because other players wouldn’t see it. Also the module is in the ReplicatedStorage

Use RemoteEvents to replicate the effect of character Ragdoll, or just make your module entirely serversided (like everyone do) without involving the client. So you just make a single toggle variable to make it work

Also this is what I’m getting when printing function

18:32:06.762 function: 0x29cf0308fd73f7c3 - Server - ModulesDatabase:21
18:32:06.982 nil - Client - ClientPunches:15

Evidently not if the method is used in a (was) popular framework, lol.

You cant pass functions over the network (and there is no reason to do that).

I don’t, just printing it to know if it exists or not

I will try it. Can you explain more how I can make it?

Middleware will NOT pass functions, because its thing that hardcoded in Roblox.
Middleware is used to work with arguments BEFORE your code recieves them

It’s essentially just a module script that acts like a BindableEvent. The middleware stuff can be ignored.
The other easier alternative is just to reassign the metatable when you receive the object.

So why doesn’t the client receive the module, when server does? Other module uses the same method and it is working, except RagdollModule.

Just literally do the
require(game.ReplicatedStorage.Modules.RagdollModule)
On client, why you have to overengineer stuff so bad

evs.RagdollModuleRemote.OnServerInvoke = function (p, name, ...)
	return require(game.ReplicatedStorage.Modules.RagdollModule)[name](...)
end

that worked for me

you are literally giving client the option to run the server code of that module script :sob:
This is so unsecure, imagine an exploiter just run this throught every player in game, softlocking them in the ragdoll state

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