I made a localscript that uses loadstring so people can put their own code in it, but it just says “loadstring() is not available”. Is loadstring not allowed in localscripts? And, if it is, what alternatives do I have?
Did you enable Loadstring() in ServerScriptService?
Yes, I did. I think that loadstring() might just not be allowed in localscripts.
I believe they can only be used by the server. Use RemoteEvent to run the code requested from the client onto the server.
I know what RemoteEvents are, but I want to run the code on the client.
I believe it’s impossible to run it on the client.
oof, Is there any alternatives?
There isn’t any alternatives that I know of.
https://devforum.roblox.com/t/question-about-loadstrings/34660/8
loadstring is not necessary to run code on the Client
This clearly doesn’t work for the use case OP is asking for (letting players input custom scripts), not sure why you’re linking this. It’s not relevant here.
Um… I’m trying to make it so users can write their own code…?
I guess I didn’t read your post well enough,
You can also send the string from a Client to the Server, run that string as code on the Server using loadstring()
The error was due to the fact that loadstring cannot be used locally because Roblox removed the compiler from the Client, so you can’t run code using loadstring on the client
Posts about running code from local input exist
Here’s some posts
Take a look at this resource, it requires loadstring to be enabled
I also asked if not, then is there any alternatives?
Yes, there are some modules around that emulate Lua execution that can be used on the client.
Adonis uses a “loadstring module” which does this and can run on both server and client, and an user on the forum shared a project called vLua I think that also works.
This solution tend to be a bit slower, and doesn’t behave the exact same as vanilla Lua, but it should solve your issue.
Can I please have link to that?
https://www.roblox.com/library/4689019964/vLua-5-1-improved-VM
Reinitialized maintains this one, so if you have any issues using it you can probably ask him.
Yeah I know that by now, but the downside of doing that is they can basically run anything on the server