Stephex_s
(Stephex)
October 18, 2022, 3:08pm
#1
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.
AlbertSeir
(AlbertSeir)
October 18, 2022, 3:14pm
#2
Are asking if you can call a client from the server
Because the answer is yes.
AlbertSeir
(AlbertSeir)
October 18, 2022, 3:19pm
#3
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
DasKairo
(Cairo)
October 18, 2022, 3:27pm
#4
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
Stephex_s
(Stephex)
October 18, 2022, 3:30pm
#5
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.
DasKairo
(Cairo)
October 18, 2022, 3:32pm
#7
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
Stephex_s
(Stephex)
October 18, 2022, 3:39pm
#8
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.
DasKairo
(Cairo)
October 18, 2022, 3:42pm
#9
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
Flonkify
(Flonk)
October 18, 2022, 3:54pm
#10
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
Stephex_s
(Stephex)
October 18, 2022, 3:57pm
#11
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.
Stephex_s
(Stephex)
October 18, 2022, 4:41pm
#12
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.
Flonkify
(Flonk)
October 18, 2022, 4:55pm
#14
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.