Is there any way to execute localscript code from a server script?

I want to know if there is any way to execute LocalScript code from a server script. I am attempting to achieve getting the text from a TextBox in a server script. I know that it can be easily done with a LocalScript, but I am wondering if you can do it with a server script in ANY WAY. I know you can’t read client values (aka the text in this case) from the server, and I am well aware of client and server but is there any way to make the server script act as a LocalScript for a certain part of the code? Any help or solution would be appreciated.

2 Likes

Use a remote event and fire it from the client side.
Local Script:

local event = game.ReplicatedStorage.Event
event:FireServer(textbox.Text)

Server Script:

local event = game.ReplicatedStorage.Event
event.OnServerEvent:Connect(function(plr,text)
print(text)
end)
2 Likes

No, without remotes or any kind of events. Making a server script as if a certain part of it is client.

No, since localscripts run on a client machine, not server. However the compiler was removed from the client, so it is not possible for the client to compile code. Only the server can do that.

You can use a custom Lua-in-Lua VM though, i.e.

Modules run at the level and state they are required at, so if I use a Lua virtual machine I would just get a server code.

following up from what @top_mono stated, you could fetch the player on the server and then do something like so;

local read_text = player.PlayerGui.path_to_txt

Won’t work, GUI text in textboxes is client-only.

if you have the local player value you can go into playergui.

Actually I think I just thought of a solution myself. @sjr04 you reminded me of something. I can require a module on the server that copies a LocalScript that does the action and then sends to server via a remote event. Thanks!

2 Likes

It would work because you are grabbing the text from the client and sending it to the server.

You can’t do this without doing some sort of communication between the server and client. This means that you have to use either value objects or RemoteEvents.

Can you please provide a way to do this (Example: Showing us code for a Script in ServerScriptService that does what you described (require a module on the server that copies a LocalScript that does the action and then sends to server via a remote event.)