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!