Ok, so basically this I'm having a bad time trying to fix this.
I have a Module script called "ServerPlayer" (used in a non-local script in the workspace), which contains a set of functions (ServerPlayer:addPlayerRequest(), ServerPlayer.setStatusRequest()...). I have a RemoteEvent object which the player requests any function of this module. For example, a player could add itself by running "remoteEvent:fireServer('addPlayerRequest',LocalPlayer.Name)". This is my code:
ServerPlayer = require(game.ReplicatedStorage.Classes.Core.ServerPlayer)
local serverPlayer = ServerPlayer.new()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
function runRequest(player, functionName,...)
print("Request from player "..player.Name.." received! Function name: "..functionName..". Args:",unpack({...}))
serverPlayer[functionName](...)
end
remoteEvent.OnServerEvent:Connect(runRequest)
However, for some reason, whenever a player sends a requests from a local script and calls any function, the self clause within the module becomes null for some reason. For example, the module has a property called "LocalData". Whenever a player requests to call the addPlayer function, It prints the following error:
ReplicatedStorage.Classes.Core.ServerPlayer:31: attempt to index nil with 'LocalData'
An exception is returned because of "self.LocalData". However, whenever I call manually this function by writting something like:
serverPlayer:addPlayerRequest("Player1")
It works fine, but when I do It like:
serverPlayer["addPlayerRequest"]("Player1")
The self clause becomes null and the code fails. Any idea of how to fix this? (Sorry for my english)
