✓ Accepted answer
ReplicatedFirst is a datamodel that is replicated to the client first, the moment they join the game (such as supplying loading screens to the player) and then the server last.
ReplicatedStorage is a datamodel in which both the client and server can access.
There's not much to it.
Otherwise, RemoteEvents and RemoteFunctions are extremely useful in transferring data from localscripts to serverscripts and serverscripts to localscripts-and back again!
Let's say we have a RemoteEvent in ReplicatedStorage (I recommend storing them in here) called ChangeMaterial.
When you click on a GUI's textbutton, it will fire that remote event.
When the remote event is fired, a part named "Part" will change it's material to Neon and make a temporary Message in the game saying what the player did.
Let's do it:
In your localscript:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
game.ReplicatedStorage.ChangeMaterial:FireServer()
end)
In a serverscript:
game.ReplicatedStorage.ChangeMaterial.OnServerEvent:connect(function(player)
game.Workspace.Part.Material = Enum.Material.Neon
local msg = Instance.new("Message",game.Workspace)
msg.Text = player.Name .. " has just changed Part's Material to " .. game.Workspace.Part.Material
wait(3)
msg:Destroy()
end)
What about RemoteFunctions? They return things. Let's say you're doing addition and want to return a calculation. (Of course calculations can be done in any type of script-yet this is an example).
Localscript is simple.
In your localscript:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
print(game.ReplicatedStorage.RemoteFunction:InvokeServer(3,5))
end)
In a server script:
function game.ReplicatedStorage.RemoteFunction.OnServerInvoke(player,arg1,arg2)
return arg1 + arg2
end
As you can see it's quite simple.
There's tons and TONS of questions about ModuleScripts so I suggest using the search bar in the top right and looking for once.
Answers above me, learn to have effort.
1 comment
Go to the wiki for this, not Scripting Helpers.