Error "attempt to call a nil value" on the client when calling the module

you could always pass through the name (a string value) of the function you wish to run from the client to the server and hold all functions inside of a table on the Server (or a Server-Side module)…

SERVER SCRIPT (basic example)

local remote = game.ReplicatedStorage.RemoteEvent
local part = workspace.Part

local functions = {
	
	ChangePartColor = function()
		part.BrickColor = BrickColor.random()
	end,
	
	ChangePartShape = function()
		part.Shape = Enum.PartType.Ball
	end,
	
	ChangePartSize = function()
		local x = math.random(0, 20)
		local y = math.random(0, 20)
		local z = math.random(0, 20)
		
		part.Size = Vector3.new(x, y, z)
	end,
}

remote.OnServerEvent:Connect(function(player, action)
	functions[action]() -- we find the "action" name inside of the functions table and run it from here as long as it exists
end)

LOCAL SCRIPT

local remote = game.ReplicatedStorage.RemoteEvent

remote:FireServer("ChangePartSize") -- make sure this matches the name of the function inside of your "functions" table in the Server Script
remote:FireServer("ChangePartColor")
remote:FireServer("ChangePartShape")
2 Likes