I came up with a possibly benefitial or doomed idea, haven’t found out yet, of sending remote events via a remote event to server. Why? So that instead of every variable that the server needs going through a single remote-event, which may cause over-fills, the client would make a remote event then send it to the server to be connected to.
Yet the incoming variable is nil.
I may have an idea in that it is a client-only object and the server can’t see, but if that’s the case, then how do I perform my concept?
local controller = Instance.new('RemoteEvent')
local givctrl = game.ReplicatedStorage.GiveControl
givctrl:FireServer(controller)
controller.OnClientEvent:Connect(function(y)
print(y)
end)
Server
local givctrl = game.ReplicatedStorage.GiveControl
local CachedCtrls = {}
givctrl.OnServerEvent:Connect(function(plr,y:RemoteEvent)
y:FireClient(plr,'yeppp') -- this is just to send back, I am not going to send back to the client when i use it.
end)
You cannot send a :FireServer() from a ServerScript. You can techinally connect it to a client script and make it do that, BUT it is very easily exploitable and not recommended.
Are there any other methods to prevent possible remote-event event-overflow? For context I need this for a plane system, as user inputs come from client and physics need to be simulated on server.
Should I instead make a RemoteEvent on the server then send it down to the client whom can then fire it?
If you’re planning to use Inputs, you could possibly make a RemoteEvent, where you can attach a name of an act to occur. It should be the best attempt I can think of for you to try.
Sending a newly created remote event object over to the server will result in the server receiving it as nil. This is set by Roblox, and cannot be changed, since sending an instance to the server as a client is a massive security risk (from an exploiter’s perspective, you can practically send anything over instead of the intended remote event).
My recommendation is to:
have the client request a controller to be made by the server
have the server make a controller
have the server send the controller back to the client via :FireClient(), the server is allowed to pass instances back to the client, just not the other way around
Remote events or instances created by the client can’t be seen by the server, so what your passing through your :FireServer() argument is nil for the server
Here is my result! For now this just takes the input from user then prints it which is just to showcase what I’d be using it for:
Client
local LPlr = game.Players.LocalPlayer
local PlanesF = workspace.planes
local givctrl = game.ReplicatedStorage.GiveControl
local controller : RemoteEvent = givctrl.OnClientEvent:Wait()
local uis = game:GetService('UserInputService')
local KeyReq =
{
Enum.KeyCode.A,
Enum.KeyCode.S,
Enum.KeyCode.D,
Enum.KeyCode.W,
Enum.KeyCode.G
}
uis.InputBegan:Connect(function(input,pr)
if not pr then
if table.find(KeyReq,input.KeyCode) then
controller:FireServer(KeyReq)
end
end
end)
Server
local givctrl = game.ReplicatedStorage.GiveControl
local CachedCtrls = {}
local ConnectionCache = {}
local function GetInput(plr:Player,input:Enum.KeyCode)
print(input)
end
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
local NewControl = Instance.new('RemoteEvent')
local cnc = NewControl.OnServerEvent:Connect(GetInput)
ConnectionCache[plr.UserId] = plr.UserId
givctrl:FireClient(plr,NewControl)
end)
game.Players.PlayerRemoving:Connect(function(plr) if ConnectionCache[plr.UserId] then
ConnectionCache[plr.UserId]:Disconnect() end end)
Rewrote the script and it works properly this time, I had to give the remote-events a parent in RepStorage, meaning that anyone could fire it. To combat that, if a player fires another player’s remote, they will get kicked. The terms are harsh because it would not happen in any normal situation.
server:
local givctrl = game.ReplicatedStorage.GiveControl
local CachedCtrls = {}
local ConnectionCache = {}
local function GetInput(plr:Player,input:Enum.KeyCode,iPlr:Player)
if plr.UserId == iPlr.UserId then
print(input)
else
plr:Kick()
end
end
game.Players.PlayerAdded:Connect(function(plr)
local NewControl = Instance.new('RemoteEvent')
NewControl.Parent = game.ReplicatedStorage.ctrls
givctrl:FireClient(plr,NewControl)
local cnc = NewControl.OnServerEvent:Connect(function(a,b)
GetInput(a,b,plr)
end)
ConnectionCache[plr.UserId] = cnc
end)
game.Players.PlayerRemoving:Connect(function(plr) if ConnectionCache[plr.UserId] then
ConnectionCache[plr.UserId]:Disconnect() end end)
Client:
local LPlr = game.Players.LocalPlayer
local PlanesF = workspace.planes
local givctrl = game.ReplicatedStorage.GiveControl
local controller : RemoteEvent = givctrl.OnClientEvent:Wait()
local uis = game:GetService('UserInputService')
local KeyReq =
{
Enum.KeyCode.A,
Enum.KeyCode.S,
Enum.KeyCode.D,
Enum.KeyCode.W,
Enum.KeyCode.G
}
uis.InputBegan:Connect(function(input,pr)
if not pr then
if table.find(KeyReq,input.KeyCode) then
controller:FireServer(input.KeyCode)
end
end
end)