Need Functions Called On Server That Are Stored On Client?

I have this table that contains my functions that are to be called on the server. the problem is how do I call these functions that are on the client table on the server?

Example

local FunctionTable = {
	CreatePart = function()
		local part = Instance.new("Part")
		part.Name = "ServerSide Part"
		part.Parent = workspace
	end
}

RemoteEvent:FireServer("CreatePart")

How would I call createpart?

This is also the same for my module scripts there is the setup function that creates a function in the FunctionsTable that is to be called on the server.

So, how do I get functions table to server. I have thought about using fire clients so. When the String of createpart is fired to server it calls FireAllClients(“CreatePart”) so it create parts on all clients to create the effect of a serverside call but I am not familiar with FireAllClients or FireClients so if anyone could help me out with this is would be nice.

I am very stuck and I have been looking for a solution for a long time.

Example of what I mean with FireAllClients although I do not know if it will work?

local FunctionTable = {
	CreatePart = function()
		local part = Instance.new("Part")
		part.Name = "ServerSide Part"
		part.Parent = workspace
	end
}

RemoteEvent:FireServer("CreatePart")

RemoteEvent.OnClientEvent:Connect(function(Name)
	FunctionTable[Name]()
end)

--Server

RemoteEvent.OnServerEvent:Connect(function(Name, ...)
	RemoteEvent:FireAllClients(...)
end)

The FireAllClients works but the physics makes the parts fall in different locations. Bue I think it might work for some of my functions

I think there is a way easier way to run functions, and it’s not necessary to put it in a table.
And I see another big flaw with the code, that you have the code stored on the client. That means it’s really easy to exploit it.

So here’s my idea how you could do it.

--------------------------------------
-- Local script

local event = game.ReplicatedStorage:WaitForChild("CreatePart") -- the path to the remote event

event.onClientEvent:Connect(function(code) -- fires when the event is fired from the server
	if code == "createPart" then -- a if statement, and checks what is the code, in this case code = "createPart"
		local part = Instance.new("Part")
		part.Name = "ServerSide Part"
		part.Parent = workspace
	end
end)

--------------------------------------
-- Server script


local event = game.ReplicatedStorage:WaitForChild("CreatePart") -- the path to the remote event

while wait(5) do -- i just put here for demonstration
	event:FireAllClients("createPart") -- fires the remote event, with a string inside
end

Please tell me if this is what you’ve been looking for!

I will as soon as you tell me how this is exploitable as this is just an example and I have sanity checks and remote event protection

Simply I said that because the most important rule, never trust the client.
Any code that is running on the client can be modified.

The example was good, but you shouldn’t do that way, what you did in the example.

1 Like

Use modules! You can require them both on server and client, I feel like it’s the perfect use case for you at moment.

I said thats where I store the functions that are needed on the server plus FireAllClients is the solution