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

How do I make it so things that happen in localscripts shows for everyone?

Asked by 4 years ago

Hi!

I was just wondering if there is anyway I can make things that happens in local scripts show for everyone on the server. I have a part that gets deleted when a player presses R. But it only deletes that part for the player which clicks it. So I want to know if I can make localscript things happen for everyone.

2 answers

Log in to vote
0
Answered by 4 years ago

Use Remote Events or Functions. They are used to communicate between the server and the client. For example:

LocalScript:

game.ReplicatedStorage.RemoteEvent:FireServer()

Regular/Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    local part = Instance.new("Part")
    part.Parent = game.Workspace

    print(player.Name .. " made a part!")
end)

The player parameter automatically is made when an event is fired.

0
Thank you! NoteSalad 17 — 4y
0
Please accept mine or iuclds' answer. youtubemasterWOW 2741 — 4y
Ad
Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
Edited 4 years ago

Code running from the client won't actually create an object that replicates to every other playing client. That's why there's something called Remote events.

Remove events are a easy way to run code onto the server, however, the replication is not always instant. To make it instant, all you have to do is run it on the client first, then the server, and whitelist every other player. Key information.

But to stay on topic, youtube's code is very simple. All you have to do is copy it and see what it does. The server always prints stuff in a green tag, and the client prints stuff in a blue tag.

Running this code will create the part onto the server

game.ReplicatedStorage.RemoteEvent:FireServer()
print('Fired')

Put this code in a server script.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
    local part = Instance.new("Part")
    part.Parent = game.Workspace

    print(Player.Name .. " made a part!")
end)
1
Thank you, I'll try it out! NoteSalad 17 — 4y

Answer this question