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

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

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! ;)

1 comment

0

Go to the wiki for this, not Scripting Helpers.

3 answers

✓ 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() -- 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.

1 comment

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.

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...

1 comment

0

Any ReplicatedFirst/ReplicatedStorage knowledge in there?

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