How would I convert the source to a script?

So basically I have a pastebin url that I am using to retrieve a source. I am getting the paste using http requests and it works fine. How would I get that whole paste to be converted over to my scripts source? Pastebin URL contents:

function testFunc(param1)
  print(param1 .. "HTTP REQUEST SUCCES")
end

How would I get this paste to “appear” in my source code so I can call the functions?

You will need a plugin to do this, first off, since only plugins and command bar can access it, but this doesn’t really seem appropriate for command bar so we’ll leave that one.

You would just do something like

local source = HttpService:GetAsync("https://pastebin.com/raw/EPVyj58n")

then get a script or create a new one then do

some_script.Source ..= "\n\n" .. source

This will just append 2 newlines then the source of the function, so it is readable. But do you really need this ? Can’t you maybe use a module and require by its ID instead?

1 Like

What I meant to say was that I just want to be able to call the functions from the retrieved source. Is there any way I can do this without resorting to plugins? Also what do you mean by using modules?

Upload a standalone ModuleScript to roblox.com, name it MainModule, then require the module by its ID then call the function.

For example

local f = require(6406496174)
f("a")
1 Like

Ah I get what you mean but for this resource I am making, it requires a http link to retrieve updated and current data and modules wouldn’t work.

Then you have no other way other than plugins, you won’t be able to tack on the source of a script at runtime (it doesn’t make sense either – the script will have been compiled already)

1 Like

That is a bummer to hear. I thought there would be one way to call a function based on a retrieved source.

You could use loadstring for this actually, make sure to allow it at ServerScriptService.LoadStringEnabled, but this won’t tack on the source.

So rough code is

local f = loadstring(HttpService:GetAsync("https://pastebin.com/raw/EPVyj58n"))
f()

but it still won’t tack on the source. Just returns a function with the source being the string.

1 Like

It worked slightly however in my function it prints out the parameter and when I call the function it doesn’t print anything. The function is defined though.

Ah right, you’ll have to treat this as a module, so return the function.

function testFunc(param1)
  print(param1 .. "HTTP REQUEST SUCCES")
end

return testFunc

So you would then do

local f = loadstring(HttpService:GetAsync("https://pastebin.com/raw/n6VhZj90"))()
f("hello")

Since loadstring returns a function which would return your function, the extra parentheses are there to get the main function

it works on my machine

1 Like

Thanks, this worked. Really appreciate your help!

1 Like