So, I have seen many people ask questions how to use these, and some things that other things would work better. So, let's get started!
So, Remote events can transfer information from the client to server, server to client. However, security risks come from this. Let me show you some examples.
--Good --Local script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.Shop:FireServer('Sword') end) --Server game.ReplicatedStorage.Shop.OnServerEvent:Connect(function(player, item) if player.leaderstats.Money >= 100 and item == 'Sword' then player.leaderstats.Money = player.leaderstats.Money - 100 print(player.Name..' bought a sword!') --do stuff end end) --Bad --Local script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.leaderstats.Money >= 100 then game.Players.LocalPlayer.leaderstats.Money = game.Players.LocalPlayer.leaderstats.Money - 100 game.ReplicatedStorage.Shop:FireServer('Sword') end end) --Server game.ReplicatedStorage.Shop.OnServerEvent:Connect(function(plr, item) print(plr.Name..' bought a sword!') --do stuff end)
So, you may ask, why is the bad example bad? Well, a hacker/exploiter could fire the remote event as many times as they want, to get infinite swords. Instead, check on the server, so even if they fired the remote events with a exploit/hack, they would still lose money/not get the sword if they dont have enough money. A way I like doing it, is checking on the client, and checking on the server. That way, I can ban the player (with my banning scripts) if they fail the check on the server.
So, Remote Functions are similar to remote events. You can pass information through the client to server and server to client like usual, but you can return information. For example, lets say if you had a module script and you wanted to get info from that. If it was a module and it was not yours, you can only require that from the server. To do that, you can do
--Client print(game.ReplicatedStorage.WordScrambler:InvokeServer('some random text')) --Server function game.ReplicatedStorage.WordScrambler.OnServerInvoke(plr, word) return require(123456789).Scramble(word) --This is just an example. Don't mind the broken syntax highlighting, and that when I typed the second sentence, it instantly fixed itself and when I deleted it it became broken again. end
Another common thing is if you want to send info like client to client (must be same client) or server to server. For that, you would use bindable events and bindable functions. They work the same as remote events and remote functions, just the information can only be passed from client to client or server to server.
With all your knowledge of your scripts, ask yourself "Can I exploit my game using a local script?" If yes, then something is wrong with your events. If not, then you will have a very safe game.
I hope you found this tutorial helpful!