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

RemoteEvent:FireServer Only for 1 player?

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)

3 comments

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.

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.

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.

2 answers

✓ Accepted answer

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

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

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