I’m trying to achieve loadstring but on the client. Don’t worry about any exploits that can arise with the method you have, although I don’t want to be given a script, rather an explanation on how to do it. Or, is there another way to run code from the client from string without loadstring. I’ve already tried InvokeServer and FireServer then FireClient, although none of them seemed to work.
It is better to use loadstring()
, but you can also make a code that loads what you want to do, an example with the properties
RemoteEvent.OnClientEvent:Connect(function(instance, Property, Value)
instance[Property] = Value
end)
I want to run code that was from a string on a client, not necessarily load code.
You can use the Loadstring module (which works better). I don’t have the link for it but I know it’s free to use
I believe this is the one you are referring to:
Do you have any info on how it maybe works?
Just require the module and put () with your code, example:
require(path here)(code here)()
Sorry that I forgot to actually call the code.
vLua is a ModuleScript that allows you to run code both on the client side and the server side from a string without using loadstring(). It’s slower compared to vanilla Lua, however I’ve found that it’s not noticeable unless you’re doing something performance intensive.
Using it is pretty simple, you would first have to require the ModuleScript in the script where you want to load the string. Then you simply have to give the ModuleScript the string that you want to run as a script, and it will run the script.
loadstring = require(script.Loadstring)
loadstring("print('hello')")
If you want to catch errors while using it, you can also use it like this:
local executable, compileFailReason = loadstring("print('hello')")
compileFailReason will be the error as to why the script didn’t compile successfully.
But it works client side, there is no use for this.
I think you can always use the built in loadstring on the client, might be wrong.
Yes, that’s true. I must have misread the original post, since I thought the author was asking how to run code on the server from the client.
You would only need the event if you were trying to run code from a player’s input (ex. from a textbox) on the server and not the client.
loadstring doesn’t work on client