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

How do I assign keybinds to NPCs?

Asked by 4 years ago

I am working on a system where if you sneak up behind an NPC (and get close enough) pressing E will allow you to knock them out. I've made all the animations but I can't find a good script that will allow me to make something like this. It's vital for the stealth features of my game to function properly. Any help is greatly appreciated.

1
Use UserInputService.InputBegan and check for the E key. Note this must be used in a localscript, see https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan for more details. moo1210 587 — 4y
0
I've had a look at it but I'm quite confused, sorry iiPizzaCraver 71 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode = Enum.KeyCode.E then
        --code for playing the animation and knocking out the NPC
    end
end)
0
Thanks :) iiPizzaCraver 71 — 4y
Ad

Answer this question