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

Replicating items to server?

Asked by 7 years ago

http://i.imgur.com/bM41C0Q.jpg

look at the output

i am trying to modify the dummy using local scripts, but the items in replicated storage wont replicate because im using fe

any help is appreciated :)

1 answer

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

What You Need

You will need to setup Remote(s) in order to replicate the desired objects.

You haven't given much context on what you need to replicate exactly, so i'll give an example using a simple Part object.


Setting Up Remotes

First, you need to set up your Remote. This can either be a RemoteEvent or a RemoteFunction.

What's the difference?

Essentially, you use a RemoteFunction if your code depends on this remote firing(i.e. the rest of the localscript cannot go on without this replication process finishing). Otherwise, you're good to go with a RemoteEvent.

For this example a RemoteEvent will suffice.


Server - Sided Code

Place a RemoteEvent in ReplicatedStorage. Place a Script inside of Workspace. This script will control any server-sided code. The OnServerEvent event will fire whenever the FireServer function is called from a localscript.

Note: The 'client' argument is always passed first.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(client)
    local p = Instance.new("Part",workspace); --Part created on the server
    p.Anchored = true;
    p.Size = Vector3.new(5,5,5);
    p.CFrame = CFrame.new(0,10,0);
    p.BrickColor = BrickColor.new("Really red");
    p.Transparency = .5;
    p.TopSurface,p.BottomSurface = "Smooth","Smooth";
end)

Client - Sided Code

Second, you need to connect your Remote. This can be done, as stated before, by simply calling the FireServer function on the RemoteEvent from your LocalScript.

local createPart = game.ReplicatedStorage.RemoteEvent; --The Remote

wait(5)

createPart:FireServer(); --Call it
0
sorry i was away, but thank you for this answer. it was very clear and a better example than what the wiki offers :) trubudist 40 — 7y
Ad

Answer this question