Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I assign keybinds to NPCs?

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.

2 comments

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.

0

I've had a look at it but I'm quite confused, sorry

1 answer

✓ Accepted answer
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)

1 comment

0

Thanks :)

This discussion is preserved as it was. New answers, comments, and votes are closed.