Loadstring check?

Hello, so heres what im attempting to do.

INFO | I am trying to, trough a server script, check for wether within a specific game, the loadstring option is turned on, or turned off. Then using the info i would like to print, for example “loadstring turned on” or “loadstring turned off” depending on the result.

ISSUE | I dont know how to achieve this, theres no documentation and i dont think its possible, but if it is please let me know. Thank you!

2 Likes

Do you mean you want to know what the loadstring does and where you can find what’s in the loadstring?

There is a property in ServerScriptService called LoadStringEnabled which does exactly what you want: ServerScriptService | Documentation - Roblox Creator Hub

This won’t be very useful however, since scripts can’t modify this property anyway, and custom loadstrings exist too.

Edit: This cannot be edited/read by scripts, alternatively you can run this:

local loadstringEnabled = pcall(function()
a = loadstring("print('Hello world')")
end)
2 Likes

Sorry lol, my post was a bit confusing. Im trying to check trough a server script, if the loadstring option is enabled in the specific place, or not. If its enabled id like the script to for example print enabled, else print disabled.

Why would you be using Loadstring? It’s deprecated.

That’s the loadstring for saving/loading player data, and is deprecated in favour of DataStoreService’s save/load system

1 Like

ServerScriptService.LoadStringEnabled is toggle-able in studio but cannot be read by scripts except through the command bar and plugins. As @brokenVectors sugggested you can see if it is enabled by testing whether calling the function will throw an error.

If you need to execute code when loadstring is disabled you can use a VM instead.

Edit: Reading the LoadStringEnabled property doesn’t work for plugins or the command bar either.

5 Likes

Thank you, ill look into using a VM.

Sorry quick question, do you happen to have any info/documentation on how to use this VM?

This one is published as a module script by @Reinitialized, and it returns a function that you can use in pretty much the same way as the old loadstring function.

If you plan on using it I found a small error in the ‘Loadstring’ module, so you’d want to change this section of code:

local waitDeps = {
	'Rerubi';
	'LuaK';
	'LuaP';
	'LuaU';
	'LuaX';
	'LuaY';
	'LuaZ';
}

for i,v in pairs(waitDeps) do script:WaitForChild(v) end

to this:

local waitDeps = {
	'FiOne';
	'LuaK';
	'LuaP';
	'LuaU';
	'LuaX';
	'LuaY';
	'LuaZ';
}

for i,v in pairs(waitDeps) do script:WaitForChild(v) end

So it doesn’t timeout.

To run it you would do something like this:

local loadstring = require(game.ServerScriptService.Loadstring)

local func = loadstring("print('hello')")
func() -- hello

For documentation, the creator included a ‘Credits’ script inside the module with links to the source code.

2 Likes

Shoot, I thought I fixed that. I’ll do that here in a sec for the new model (still can’t update the old one thanks to new UI)

3 Likes