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.

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 Problem
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 Script
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 Pattern
Here's the secret pattern that makes it work:
How it works:
- FiveM looks for exports using the pattern
__cfx_export_ResourceName_ExportName - When another script calls
exports['LegacyFuel']:GetFuel(), FiveM triggers the event__cfx_export_LegacyFuel_GetFuel - Your handler receives a
setCBcallback function - You call
setCB(yourFunction)to provide the actual function - The calling script gets your function and everything works perfectly!
Complete Working Example
Let's say you want to replace LegacyFuel with your own custom fuel system. Here's how to maintain compatibility:
Supporting Multiple Scripts at Once
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 Replacement
Based on the actual LegacyFuel exports, here's a complete replacement that maintains 100% compatibility:
Testing Your Legacy Exports
After setting up legacy exports, test them with this simple script:
Common Issues and Solutions
"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 Superior
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 Practices
- Start early in server.cfg - Put your compatibility resource before other resources
- Document your exports - List what legacy exports you support
- Test thoroughly - Verify all dependent scripts still work
- Keep it simple - Don't overcomplicate the compatibility layer
- Plan for deprecation - Eventually migrate scripts to use modern exports
Conclusion
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!
Sources
- LegacyFuel Official Repository
- FiveM Exports Documentation
- Personal experience
- Community discussions
Related posts
Have questions about this post?
Ask on Discord

