I am making a game where if you are touching another player and clicking a key, then it plays an animation and gives the other player velocity. The problem is, I can't find a way to say "Am I touching another player? If so, give that specific player velocity." If anyone could help, that would be greatly appreciated.
✓ ANSWER ACCEPTED
Give velocity to a HumanRootPart when touching?
1 answer
✓ Accepted answer
--Services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Variables for Player and Mouse
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
--Event that checks for input
UserInputService.InputBegan:Connect(function(input, proc)
if not proc then
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.E then
--Check if target is valid
if Mouse.Target and Mouse.Target.Parent then
local Targetted = Players:GetPlayerFromCharacter(Mouse.Target.Parent)
if Targetted then
--Fire event to server, go crazy
end
end
end
end
end)
I'm assuming you had an issue figuring out how to get a player, so I drew something up.
UIS handles input detection, and the InputBegan event gets whatever input that was initially pressed. From there you just simply need to get the mouse of the player, check if the target exists, and go from there. If you have a question about any of this let me know!
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
https://developer.roblox.com/en-us/api-reference/class/UserInputService || https://developer.roblox.com/en-us/api-reference/class/Mouse || if you want to know more about these two, here are the links! Note that UIS is the preferred option almost always as it has better functionality.
I read all of the articles and looked through the code. Very helpful! Is this just saying: If the keyboard input is E, then if the mouse is pointing at a player, then it fires an event to the server that fires it to the player that now gets velocity?
Exactly.
Thanks!