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

Give velocity to a HumanRootPart when touching?

Asked by 4 years ago

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.

1 answer

Log in to vote
0
Answered by
waifuSZN 123
4 years ago
--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!

0
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. waifuSZN 123 — 4y
0
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? blarp_blurp645 63 — 4y
0
Exactly. waifuSZN 123 — 4y
1
Thanks! blarp_blurp645 63 — 4y
Ad

Answer this question