I am trying to make a medkit and I have to use a remote event to give the player 100 health, so I'm in the server script service scripts and in one of the scripts, I'm trying to find the person who fired to the server and used the medkit by typing in: local Wielder = script.Parent.Parent.Workspace.Medkit.Parent.Parent:FindFirstChildWhichIsA("Humanoid") I tried it in different ways and I can't figure out how to find the player who fired to server.
The simplest way to accomplish this is to use the built-in arguments for the RemoteEvent. When a player fires a server event, it can carry across any arguments that you want.
local remoteEvent = game.ReplicatedStorage.RemoteEvent remoteEvent:FireServer(argument1, argument2)
On the server side, there is an extra argument that is reserved for the player who fired to the server. When attaching this to a function, the first argument is the player.
local remoteEvent = game.ReplicatedStorage.RemoteEvent function medkit(player, argument1, argument2) -- The server recieves a player argument! -- Function code here end remoteEvent.OnServerEvent:connect(medkit)
So, to get the player's character in the workspace, all you have to reference from here when coding the function is player.Character
.
For more information about RemoteEvents and RemoteFunctions, I recommend you check out this page on the developer documentation. It will provide more in-depth information on how these arguments can be applied.