A remote event is a 1 way connection with your target of choice. If fired from a local script, a remote can only send to the server. if fired from the server, it may only send to every client or an individual one.
e.g say you had a remote event in replicatedstorage
Local script:
script.Parent.ClickDetector.MouseClick:connect(function()
local variable == 'urfatmum'
game.ReplicatedStorage.remote:FireServer(variable)
end)
arguments are the hardest part of remotes, by far. Arguments are optional, however whatever you're trying to send put it on the fire server part.
Server script: (the reciever in this case.)
game.ReplicatedStorage.remote.OnServerEvent:connect(function(player, newnameforvariable)
print(newnameforvariable)
workspace.Part.BrickColor = BrickColor.new("Black")
end)
Now let's talk about those arguments. We fired a variable from the client, but we have a player now??
Whether a remote event or remote function, you must ALWAYS have a player argument on the receiving end.You don't need to send over a player value, it'll do it for you. Make sure the player is the first argument on the reciever, so you don't accidentally name something wrong.
On the receiving end you may name the arguments whatever you want if it helps.
Let's talk remote functions, my personal favorite. Say we wanted to do the same thing as last time, but if everything went okay we'd send over a gui saying all went well.
Same setup as last time, local script:
script.Parent.ClickDetector.MouseClick:connect(function()
local variable2 == 'urfatmum2'
local diditwork = game.ReplicatedStorage.remotefunc:InvokeServer(variable2)
if diditwork == 'shutup' then
game.ServerStorage.Gui = game.Players.LocalPlayer.PlayerGui
else
warn("oh frickkkk")
end
end
end)
Notice how we named the invokeserver part something? You can go without naming it, but if you want to send Data back via a 2 way connection, assign your function to a variable.
Server script:
game.ReplicatedStorage.remotefunc.OnServerInvoke = function(player, variable2)
local yes,no = pcall(function()
workspace.misspelledpart.poop = fart
end)
if yes then
return 'shutup'
else
print("somethn went wrong chief: "..no)
return false
end
end
end
What we just did is recieve an invoke, and pcall an incorrect operation thus not actually doing the function correctly, by making use of return we can return something to our if statement back on the local script. If our function ran okay we'll send that it worked and on the local script give us a gui. If it didn't work, we'll return false.
I didn't cover a lot, but that's a general idea?