Loadstring() is not available

What do I want to achieve?

I want to achieve a fully functioning console bar (not an admin system, only for code).

What is the issue?

loadstring() is not available for some reason. It gives an error when it reaches line 18, and it says this:

What solutions have I tried so far?

I’ve enabled loadstring(), but however it is not working at all.
Screenshot 2025-02-06 231943

Code:

game.UserInputService.InputBegan:Connect(function(inputObject, gameProcess)
	if gameProcess then return end
	
	if inputObject.KeyCode == Enum.KeyCode.Semicolon then
		script.Parent.Parent:TweenPosition(UDim2.new(0.125, 0, 0.125, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.5, true)
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
		script.Parent.Text = ""
		task.wait(0.5)
		script.Parent:CaptureFocus()
	end
end)

script.Parent.FocusLost:Connect(function(EnterPressed)
	if not EnterPressed then return end
	
	script.Parent.Parent:TweenPosition(UDim2.new(0.125, 0, -0.125, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 0.5, true)
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
	local LoadedString = loadstring(script.Parent.Text)
	LoadedString()
	print "Done!"
end)

Any way to fix this?

loadstring returns a function so instead of doing loadstring(script.Parent.Text) use loadstring(script.Parent.Text)()

if your problem is not resolved than use this module vLua: Loadstring reimplemented in Lua

As stated by @MichaAndersan, you should add a bracket at the end to execute the thread. Your script seems to be client sided aswell, loadstrings only work in server scripts for security and reliability.

2 Likes

Your issue stems from using a LocalScript. Under the client runtime context, you will need to use an Lua in Lua virtual machine such as vLua.

Like the others said, loadstring only works on the server, and you can fix this by sending the text to the server and running it on the server. However I’d like to point out that this can put your game and account at risk. Anyone will be able to run code which can allow people to create TOS breaking content which will get the game and your account banned.

I will make it for developers only.

I’ve removed loadstring() inside the client script and put it inside a BindableEvent inside ReplicatedStorage, but it does NOT work!

BindableEvent’s code:

--!nocheck

script.Parent.Event:Connect(function(Script)
	loadstring(Script)()
	print("checking to see if this works :D")
end)

Client’s code:

game.UserInputService.InputBegan:Connect(function(inputObject, gameProcess)
	if gameProcess then return end
	
	if inputObject.KeyCode == Enum.KeyCode.Semicolon then
		if game.Players.LocalPlayer.Name == "DomonicJ06" or game.Players.LocalPlayer.Name == "error12345307" or game.Players.LocalPlayer.Name == "Dragon_head2346" then
			script.Parent.Parent:TweenPosition(UDim2.new(0.125, 0, 0.125, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.5, true)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
			script.Parent.Text = ""
			task.wait(0.5)
			script.Parent:CaptureFocus()
		end
	end
end)

script.Parent.FocusLost:Connect(function(EnterPressed, Input)
	if not EnterPressed then return end
	
	game.ReplicatedStorage.LoadString:Fire(script.Parent.Text)
	
	script.Parent.Parent:TweenPosition(UDim2.new(0.125, 0, -0.125, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 0.5, true)
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
	print "Done!"
end)

BindableEvents only fire on the same side of the server-client boundary. In this case, it’s still trying to loadstring on the client. Use a RemoteEvent and make the event handler a Script so it’s ran on the server.

2 Likes

Just make sure you do a sanity check on the server so that no exploiters can abuse the remote and execute server side code

You need to use a RemoteEvent for this, not a BindableEvent as bindable events fire on the same environment they are called in (client or server), however RemoteEvents can send messages from the client to the server and vice versa.