What do you want to achieve?
I want to get module required on server from client
What is the issue?
In the server script, it prints the module functions. However on the client, it prints nil
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
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
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
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.
you are literally giving client the option to run the server code of that module script
This is so unsecure, imagine an exploiter just run this throught every player in game, softlocking them in the ragdoll state