Any workaround for loadstring to client side?

I want to be able to use Pastebin for client sided local scripts, and therefore wanted to ask if there is some type of workaround for loadstrings for the client side.

Here is a load string module for Lua but it doesn’t really support Luau.

These might also be options, though I’m not sure if they’re finished or if their format is compatible with Roblox:

As far as I know, the only way to do this is to use a custom loadstring module that you can require and use on the client.

It might be possible to do something where you remotely publish a ModuleScript and require it by id. (That would require sending the code to the server to send to an external server and then have the external server send back the module id though.)

If by the last part you mean requiring a module that has the loadstring in it, that wouldn’t work I don’t think unless you mean something else?

I don’t know if its related to this but if im using a UI Library that uses a loadstring linked to a pastebin in roblox Studio i just paste the source code into the module and require that in the local script so the module script basically acts like the pastebin from there maybe convert it as a package if you want to update it? idk if this could be a use of help in your scenario though

Unfortunately it doesn’t, as I want the code to always be on Pastebin, not in the module script.

You could take their code and publish a ModuleScript (named “MainModule” so you can require it by ID) on a bot account through automation.

Then you could have a LocalScript require the module in game by ID (e.g. require(123456789) but though a function that takes an arbitrary ID).

This would run their code, but it would be challenging. (It’s both complicated to set up and there are potentially moderation risks/challenges.)

I need the code to be specifically from Pastebin. The reason is because I am coding something that multiple people will use, and I want to be able to update/control the code from a platform like Pastebin.

you can still fetch URLs from the server via a remote function then loadstring it with one of those VMs on the client. are you limited to specifically only the client?

You can make an ID-required module then update the module asset. You could have it be automatic or you could just do it manually.

For example:

  • When you make changes to the code in paste bin
  • Upload an update to your MainModule asset
  • All of the games etc that require your module by ID will then use the updated version

Edit:

Per the docs:

If a ModuleScript is uploaded to Roblox and the root module has the name set to MainModule, it can be uploaded as a model and required using require() with the model’s asset ID. Then it can be loaded into your experience, although this logic only works on the server and will error on the client. If other users want to use the module, it must be public.

It looks like this functionality only works on the server :confused:

I still don’t see the reason why not to use ModuleScripts?

Make your system or whatever in a module script, publish the module script, import it to your client, not via script, direct import.

When you need to change something, update the module with new module, tell your friends to reupload, and that’s it.

Also IIRC you can still require(id) within ReplicatedStorage

There is no way (at least not by design) to directly use Loadstring on the client.

What would work though, and this is something I’ve actually been working on for a while, is to make your own scripting language that has it’s interpreter implemented in Luau. From there you can just use HTTPService to get the script from pastebin, send it over to the client, and interpret it there.

You could also write your own Luau compiler and interpreter which runs on the client, someone did create a Lua compiler in Lua a while back, so I think this would be possible. From there you just get the pastebin content from HTTPService and send it to the client like before.

Both of these options require pretty advanced knowledge of programming, both of them are also pretty slow performance-wise, and unfortunately I don’t think there’s any easier ways to do this. It’s worth noting that if you just want to have nothing more than atomic updates for scripts, you can just use packages. (Though these require a place to be republished when they’re edited.)

1 Like

What’s the point of this? Technically, you can just use a modulescript. If I’m not stupid (I probably am), you can get the code from pastebin and make it into a function in a modulescript.

1 Like

To repeat myself, I need the code to be specifically from Pastebin. The reason is because I am coding something that multiple people will use, and I want to be able to update/control the code from a platform like Pastebin.

1 Like

use vLuau, and make a custom isolated environment. im using this module for my recent project. and im currently try to find some good looking textbox ui suitable for scripting inside roblox.

the environment should declare the basic functions like print, color3, game, etc.

local env = {
    print = print
    --[[ YourOwnFunction=function() 
        print("example")
    end]]
    workspace = game.Workspace
    game = {
         -- put some services that can be used.
         -- Workspace = game.Workspace
         -- ReplicatedStorage = ...
    }
}

-- Pass them onto the loadstring module
local loadstring = require(...) -- path to module
local success, err = pcall(function()
    local loaded = loadstring("--[[your code goes here]]", env)
    loaded()
end)

also, regarding on your usecase, if you want to use pastebin (winch requires httpsservice) in client side, try make a custom function on the game virtualized “enviroment” that fire a remote event or a remote function when it was used.

after that, use the http results that was sent to the client trough the remote function to put them in the loadstring.

In reading some of the posts, you can use HttpService to get the code from Pastebin, then use an LUA compiler on it. Then you can send the bytecode to the client and run it from a bytecode interpreter.

This contains everything that you need to get started:

Loadstring.rbxl (296.8 KB)

What you are looking for is in game.ServerScriptService. This code is quite old, but it still works. You need to use FiOne.lua for right now. FiThree is a newer compiler, but the interpreter doesn’t support it.