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