Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a remote event execute code?

I am making a coding game where you will be able to have a little GUI that lets you run code to try to fix a problem, but I need to then have that code run on the server with a remote event. This is where I have been stuck. So far I have this on the local side:

game:GetService("ReplicatedStorage"):WaitForChild("ScriptRunRemote"):Fireserver(function()
	print("Ran Code!")
end)

But I don't know what I could put on the script to get that code and run it.Thanks in advance for any help.

2 comments

0

Don't, exploiters/ hackers will have the ability to execute server code (code that others can see)

0

but if you want to, use loadstring("code here")()

1 answer

✓ Accepted answer

First, you must capitalize the S in the FireServer function; otherwise, you will get an error because there is no such thing as "Fireserver". Second, you cannot create a function in the LocalScript for the server to execute. You must do this in a Script.

LocalScript

game:GetService("ReplicatedStorage"):WaitForChild("ScriptRunRemote"):FireServer()

Script

game.ReplicatedStorage.ScriptRunRemote.OnServerEvent:Connect(function()
	print("Ran Code!")
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.