Unknown global 'loadstring'

I’ve been interested in using the loadstring function in roblox, and after spending well over 8 hours on a very strict sandbox/filter for the code, I was ready to implement loadstring and quickly found out it wasn’t working… I have LoadStringEnabled enabled and I’ve restarted the client but it still is unknown. (The code is on a server script under ServerScriptService)

It was my fault for not checking this before taking such a large task. However now I’m just trying to salvage as much of that work as possible.

(I am well aware of the risks that loadstring posses, and that’s why I spent so much effort in designing the sandbox)

The error is showing up even in this very basic script.

loadstring(‘print(“Hello World”)’)

1 Like

Please move this to #help-and-feedback:scripting-support Cool Creations is for general feedback on creations.

Please post your code so we can help you identify the issue.

Sorry it’s late and I just noticed this was the wrong channel

loadstring still exists. This is likely a studio bug. Feel free to continue using it.

Hey whats the error your getting?
Also loadstring returns somewhat of a function call; so your code would look more like

loadstring(‘print(“Hello World”)’)()

So I was very tired that night and noticed that the editor was saying loadstring did not exist. I never bothered to just run it anyways but it turns out it runs just fine, the editor will just yell at you that the function does not exist even though it does.

I shouldn’t have used the word error in my original post as I think it misled people into thinking it was throwing an error at run time rather than the editor just yelling at me.

Just so you know, loadstrings are very like a rickety process.

loadstring() is no longer a registered global and no longer “highlights” once used, it’s still functional if you enable LoadstringEnabled regardless of the warning beforehand.

However, there is a way around this!

How to use:

local Loadstring = require(path.to.module)
Loadstring("code here")

Note that by using this, you do not have to enable LoadstringEnabled.

Is it sandboxed? I don’t really see why one would use this over the original?

You Can Just Use The Vanilla Loadstring. I Do Not See The Point In Making Something That Already Exist. Since Loadstring Returns A Function You Can Do

local func = loadstring("print(1)")
setfenv(func, { wait = wait })
func()

This Would Cause A Error Since Print Is Not In The Environment Given. Only Wait Is.

Because its not enabling it replicated wise.