Hello. I was wondering can we FireClient a local function using RemoteEvent?
These are the scripts:
ModuleScript
local player = game:GetService("Players").LocalPlayer
local function test()
print("RenderStep")
end
script.Parent.RemoteEvent:FireClient(player, test())
An example of this would be, for example, to create a module with a dictionary of functions and to pass the id of the function you want to use. EX:
-- Module
local funcs = {}
function funcs.doSomeStuff()
-- Blah blah blah...
end
function funcs.doOtherStuff()
-- Blah blah blah...
end
return funcs
--[[
{
["doSomeStuff"] = function: .....
["doOtherStuff"] = function: .....
}
]]
-- Server
YourEvent:FireClient(pLayer, "doSomeStuff")
-- Client
local Funcs = require(wherever.your.module.is.placed)
YourEvent.OnClientEvent:Connect(function(func)
Funcs[func]() -- You can pass in your own parameters here...
end)