Tutorial

How to Keep Old Script Exports for Your New Script

Learn how to maintain backward compatibility when replacing existing FiveM scripts. Keep all dependent scripts working while using your improved system.

Meteo2025-07-138 min read
How to Keep Old Script Exports for Your New Script

Have you ever wanted to create your own custom script but worried about breaking all your other scripts that depend on an existing one? This guide shows you exactly how to keep old script exports working in your new script.

This method works for keeping any old script exports in your new scripts!

The Common Problemlink

Many servers use popular scripts that other resources depend on. Your scripts probably use exports like this:

But what happens when you want to use your own new script? If you stop using the old script, all these dependent scripts break with errors like:

Now you have to manually edit every script that uses those exports to work with your new script. That's a lot of work!

The Solution: Keep Old Exports in Your New Scriptlink

FiveM has a special system that lets you keep old script exports in your new script. You can make all your existing scripts work with your new system without changing anything.

The Magic Patternlink

Here's the secret pattern that makes it work:

How it works:

  1. FiveM looks for exports using the pattern __cfx_export_ResourceName_ExportName
  2. When another script calls exports['LegacyFuel']:GetFuel(), FiveM triggers the event __cfx_export_LegacyFuel_GetFuel
  3. Your handler receives a setCB callback function
  4. You call setCB(yourFunction) to provide the actual function
  5. The calling script gets your function and everything works perfectly!

Complete Working Examplelink

Let's say you want to replace LegacyFuel with your own custom fuel system. Here's how to maintain compatibility:

Supporting Multiple Scripts at Oncelink

You can also create one new script that replaces multiple old scripts. Here's an example for replacing both qb-management and qb-banking with your own system:

Now your single script handles exports from both qb-management and qb-banking!

Real-World LegacyFuel Replacementlink

Based on the actual LegacyFuel exports, here's a complete replacement that maintains 100% compatibility:

Testing Your Legacy Exportslink

After setting up legacy exports, test them with this simple script:

Common Issues and Solutionslink

"No such export" errors still happening:

  • Make sure your legacy export resource starts before other resources
  • Check the export names match exactly (case-sensitive)
  • Verify you're using the correct resource name in the event pattern

Scripts not finding the exports:

  • Ensure dependencies in your fxmanifest.lua are correct
  • Start your legacy export resource early in server.cfg
  • Check that other resources start after your compatibility resource

Performance concerns:

  • Legacy exports have minimal performance impact
  • They only trigger when actually called
  • Much better than running the original heavy script

Why This Method is Superiorlink

Compared to editing every script:

  • No need to modify existing scripts
  • Scripts continue working exactly as before
  • Easy to maintain and update
  • Can support multiple naming conventions

Compared to keeping the old script:

  • Better performance with your optimized code
  • Modern features and security
  • Easier to customize and maintain
  • Backward compatibility without the bloat

Best Practiceslink

  1. Start early in server.cfg - Put your compatibility resource before other resources
  2. Document your exports - List what legacy exports you support
  3. Test thoroughly - Verify all dependent scripts still work
  4. Keep it simple - Don't overcomplicate the compatibility layer
  5. Plan for deprecation - Eventually migrate scripts to use modern exports

Conclusionlink

Using the __cfx_export_ pattern lets you have the best of both worlds: modern, optimized scripts with full backward compatibility. You can replace LegacyFuel (or any script) with a better system while keeping all your existing scripts working perfectly.

This method saves hours of manual script editing and prevents frustrating compatibility issues. It's a professional solution that many successful FiveM servers use.

Remember: The key is the exact pattern __cfx_export_ResourceName_ExportName - get this right and everything else is easy!

Sourceslink

FiveMScriptingExportsCompatibilityDevelopmentTutorial
Share

Have questions about this post?

Ask on Discord