Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use ReplicatedFirst + ReplicatedStorage, ModuleScripts and RemoteEvents/RemoteFunctions?

Asked by 8 years ago

As the title suggests, this question involves me asking how to use the 3 - 5 things above. Let me unload the knowledge I already know:

  • ModuleScripts provide communication from client - server

And, that's it. What did you expect? Anyways, it would be great if I grasped knowledge of these five things. (Three if you combine RemoteEvents + RemoteFunctions, then combine ReplicatedFirst and ReplicatedStorage.) Thanks! ;)

0
Go to the wiki for this, not Scripting Helpers. grasheeno 70 — 8y

3 answers

Log in to vote
1
Answered by
unmiss 337 Moderation Voter
8 years ago
Edited 7 years ago

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() -- We don't need to supply the player instance as it's already sent as an upvalue
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)) -- We don't need to supply the player instance as it's already sent as an upvalue
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.

0
This came the closest, and cleared up a lot of questions. I'll need to read it through a bit, but this helped the most. RadiantSolarium 35 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Okay here are the links -http://wiki.roblox.com/index.php?title=API:Class/ModuleScript -http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial

Module Scripts: Are scripts who's functions can be called from client or server scripts. This is useful if a function is needed in both sides and makes it efficient.

Remote Events: Custom events that can be fired from a script, this lets any listeners know if there isn't a set event and you want to make your own for whatever reason.

Remote Functions: Functions that act the same as events but are functions...

0
Any ReplicatedFirst/ReplicatedStorage knowledge in there? RadiantSolarium 35 — 8y
Log in to vote
-1
Answered by 8 years ago

ReplicatedFirst: http://wiki.roblox.com/index.php?title=ReplicatedFirst ReplicatedStorage: http://wiki.roblox.com/index.php?title=ReplicatedStorage

ReplicatedFirst contains stuff that you want to be shown to the client right away, so Roblox will load anything in there first.

ReplicatedStorage is meant to be a replacement for storing things in lighting.

Answer this question