Hello ^^
So lately i made a module to create and fire modules for my game.
Yes, creating works, cause the server is creating the remotes for the client if it requests one.
The firing part is the only problem.
The Server loads first before the client, so events going to be created on the client will not work on the beginning.
This is a example of how i create them:
(Using a self made library for my projects, its just a normal module copying other function bla bla bla etc)
// Server
library:InitRemoteHandler()
library:CreateRemote("Server", "event", function(Player)
print(Player.Name.. " sended a message to the server!")
end)
players:BindFunctionToPlayers(function(Player) -- [ignore this, this is a custom function for playeradded i made]
library:FireRemote("Client", Player, "hello!") -- REMOTE WAS NOT FOUND!
end)
// Client
library:CreateRemote("Client", "event", function(message)
print(library.LocalPlayer.DisplayName.." got a message from Server! , ".. message)
end)
library:FireRemote("Server") -- works
So the problem is the server is trying to fire a remote before it was “created” as the server gets fired first.
Heres the script of :FireRemote()
function module:FireRemote(remoteName, ...)
local otherSession = getOtherSession()
local folder = remoteFolder:FindFirstChild(otherSession)
local remote : Object = folder:FindFirstChild(remoteName)
print(remote, folder:GetChildren(), otherSession)
local parametersToTable = {...}
if getSession() == "Server" and parametersToTable[1]:IsA("Player") == false and parametersToTable[1] ~= "All" then warn("First Parameter need to be a Player or All in Server Fires!", remoteName) return end
if not remote then warn("Did not find remote called: "..remoteName.." | ", getSession()) return end
if remote:IsA("RemoteEvent") then
if getSession() == "Server" and parametersToTable[1] == "All" then
table.remove(..., 1)
remote["FireAllClients"](remote, ...)
else
remote["Fire"..otherSession](remote, ...)
end
elseif remote:IsA("RemoteFunction") then
remote["Invoke"..otherSession](...)
else
warn("Type of object: "..remote.." is not supported!")
end
end
Here is what its printing! [orange message and before are important | The Server]
What should i do to fix this problem? As the server loads before the player scripts loaded.
Next Question: Should i keep on this module or is there someone that prefers that i should use a custom module like this [link with devforum would be nice].
MIND: This is just a normal simulator, so i dont need buffers remotes handlers like ByteNet, as a simulator doesnt really require it.