Is there a way to send over scripting written on server to client?

Now the title doesn’t explain my question, however let me try to give a better understanding. So, is it possible to write short client scripts on Server like this?

	local Function = function()
		print("hello")
	end
	game.ReplicatedStorage.Remotes.Test:FireClient(plr, Function)

This does not work, but I want to know if it’s possible.

Are asking if you can call a client from the server

Because the answer is yes.

Never mind. I’m an idiot and didn’t read what you were asking.

I’m not sure, I have never tried because the function should already exist on the client or server. If you want to return a value to the server or client after it being fired, then you can just use a RemoteFunction.

1 Like

If you want to use a global Function or event, use RemoteFunction for RemoteEvent,
For Example:

here i have a Server Script, i want it to prit that it has been invoked (Called) by a script:

workspace.RemoteFunction.OnServerInvoke = function()
	print("Invoked")
end

Here the Client Script (LocalScript) wil Infinitely Invoke the function:

while wait() do
workspace.RemoteFunction:InvokeServer()
end

The thing is I want to write simple client events on my server script and then transfer the coding to the client script for it to run.

You have to put it in a client script or in a modulescript that a client script requires.

You’ll need a player Instance for the script to run, otherwise youll get an error.
For Example:
LocalScript

workspace.RemoteEvent.OnClientEvent:Connect(function()
	print("Fired")
end)

Script

game.Players.PlayerAdded:Connect(function(Player) -- Our Player
	while wait() do
		workspace.RemoteEvent:FireClient(Player)
		end
	end)

You can do the same with a RemoteFunction

I don’t think you understand what I’m trying to do

	local Function = function()
		print("hello")
	end
	game.ReplicatedStorage.Remotes.Test:FireClient(plr, Function)
game.ReplicatedStorage.Remotes.Test.OnClientEvent:Connect(function(TheFunc)
-- // this is where I check the type which always returns nil.
end)

I’m trying to run a function that the client recieves from the server.

Just swap the Script from the Server Script and Client:

workspace.RemoteEvent.OnServerEvent:Connect(function()
print("Fired")
end)

workspace.RemoteEvent:FireServer()

I am reading your post, and im trying to help with that

There are some Lua VM modules out there that you could use for loading code sent from the server to client and vice versa.

This might possibly work: Lua VM - Roblox

Never heard of a LUA VM, however will take a look. Will give you solution if it gives me the result I am looking for.

Still have no clue how to use it, but will keep digging and seeing if I can get it working somehow

Why do you want to send code from the server to the client in that way?
There’s usually a beter way.

It may be a little bit tricky to get working but it allows you to do this:

Basically, imagine the raw text being what gets sent to the client from the server.