There really isn’t much you can, or should do, to optimize this. This is pretty basic code - you are literally just checking if it exists, and if it does, changing its parent. You can’t tweek it much, nor should you.
Don’t do this. Lookup caching in Lua should only be done on members you’re accessing repeatedly. This example in Lua would actually be less performant as it adds an extra allocation, yet still only does a single field lookup.
Roblox doesn’t use Lua anymore, and Luau has some quirks that actually make lookup caching an anti-optimization. Field access is inline cached, but Luau has an even more performant optimization specific to table:method() calls. (nottable.method() calls however). You can read more about that here.