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

Remote Functions serverscript and localscript questions?

Hey guys so i've started using FilteringEnabled and trying to figure it out how it works correctly

So i'm a bit confused, do i put most functions in the localscript or serverscript ? also when i test this it works but prints the "touched" only once whenever i touch it again it doesn't work. Or should i put the touched event onto the localscript not server script ?

Also i don't really get how these OnServerEvents work, because if i remove that line it could print touched all the time when it's touched

Server Script in ReplicatedStorage

local TouchEvent = game.ReplicatedStorage

local door = game.Workspace.door
game.Workspace.door.Touched:connect(function(player)
game.ReplicatedStorage.TouchEvent.OnServerEvent:connect(function()

print("touched")
	
end)
end)

LocalScript in StarterPlayerScripts

local TouchEvent = game.ReplicatedStorage.TouchEvent

TouchEvent:FireServer()

1 answer

✓ Accepted answer

#1. The FilteringEnabled

Turning FilteringEnabled on makes the LocalScripts with no capabilities of "touching" the server. Since exploiters use to hack their own client, injecting LocalScripts on it, any changes performed on it (for example, create a part) won't affect the server at all.

#2. The communication client-server

To solve this problem, ROBLOX introduced those special channels called RemoteEvents and RemoteFunctions. Translated to English, using those channels would like be:

Client: Hey server, can you run the function connected to this Remote, please? Server: Sure!

#3. How to establish connection between those scripts.

Let's imagine we have a GUI button, and we want to make it change the color of the baseplate.

So we could use a LocalScript inside of the button:

script.Parent.MouseButton1Click:connect(function()
	game.Workspace.Baseplate.BrickColor = BrickColor.Random()
end)

This would work, right? With FilteringEnabled set to true, no. The maximum that could happen is that ONLY you could see the changes. Since LocalScripts can't replicate, the server does not see those changes.

So what to do?

We could use a RemoteEvent so that the LocalScript can ask the server to run a function (defined on a Script) - since the server will perform the actual change, it will be visible to everyone on the server.

1st we need to create the RemoteEvent - this should be visible to BOTH server AND client - the Workspace is visible to both, so they can communicate through there.

So let's assume there is a RemoteEvent called RE on the Workspace

-- On the LocalScript
script.Parent.MouseButton1Click:connect(function()
	game.Workspace.RE:FireServer() -- asks the server to perform the function
end)

-- On the Script (ServerScript)
local remote = game.Workspace.RE
remote.OnServerEvent:connect(function() -- the function is runned when the LocalScript asks it to be run.
	game.Workspace.Baseplate.BrickColor = BrickColor.Random() -- performs the changes and replicates to everyone
end)

Now, the problem of the FileteringEnabled is solved!

NOTE: Server Scripts don't run very well on the ReplicatedStorage, or do not run at all.

NOTE 2: If you have any dobut, check out this documentation. It will help you:

The complete tutorial here

RemoteEvent API

RemoteFunction API

If this helped, be sure to accept it! Thank you!

1 comment

0

The explaining, i give 10/10 i will save this so i can check it out when i have problems. THANKSSSSSSS

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