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

Finding the character who is holding an item that fires to the server?

Asked by 4 years ago

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.

0
Please put your WHOLE code in the description. And, put it in code blocks, I'm getting really tired of telling people to have to put code in blocks, or having to tell people this isn't a request site. Sometimes I really wish people would read guide lines before asking something. So anyways, please put your whole code. Cynical_Innovation 595 — 4y

1 answer

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

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.

Ad

Answer this question