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