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

RemoteEvent:FireServer Only for 1 player?

Asked by
14dark14 167
4 years ago
Edited 4 years ago

Ok how can I fire a remote event from local script and make it run for 1 player on server?

local player = game.Players.LocalPlayer

game.ReplicatedStorage.RemoteEvent:FireServer(player)

server

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
    print("aa")
end)
2
If you want code that only runs for a single player, then you'll have to run that code in a LocalScript, which would be located inside of the player that you want the code to run for. Rinpix 639 — 4y
0
Also, I don't see why you're passing in the player variable when you call the FireServer function, because that's already done for you when you call the function. The first parameter received on the server end is always the player that fired the RemoteEvent. Rinpix 639 — 4y
0
If you want to use RemoteEvents, you would have to use 2, I assume. The first one would be the :FireServer(player,args) event, and the second event would be the :FireClient(player,args) event. But, this is very code heavy and can get very messy and confusing. killerbrenden 1537 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

when you call FireServer, the function fires the OnServerEvent signal with the player that called the FireServer, and all extra arguments that you pass to FireServer().. therefore, you don't need to do FireServer(player), b/c the engine does it automatically for you.

so the following should hopefully answer ur question:

LocalScript:

game.ReplicatedStorage.RemoteEvent:FireServer()

Server script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    print(player.Name," fired the server")
end)

keep in mind that LocalScripts are "local" to a player.. they run on a player's computer.. they are meant to handle all the client(player) sided things..

Ad
Log in to vote
0
Answered by 4 years ago

It's not possible to do something for one player on the server. Here is everything in a nutshell (hopefully):

Server: Every action that happens here happens for everybody in-game. If you want a server script, put it in the ServerScriptService.

Client: Scripts and other actions that happen here only happen to the local player, or the client. To do things on the client, put a local script in StarterPlayer, StarterGui, etc.

For more information about clients and servers, visit this website: https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model

Answer this question