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

How to make a key event?

On my game, I want to make a key event to where if you press "c", you get down on the floor, but slower then usual.

3 answers

✓ Accepted answer

Warning: This question could be Marked as not constructive since you have provided us with any effort of you trying to accomplish this on your own.

If you want to make a function that triggers by a certain Key then I suggest you use UserInputService and a If statement.

game:GetService("UserInputService").InputBegan:connect(function(Key,Typing)--The second argument "Typing" is a Boolean value that indicates whether or not the Player is Typing.
	if Typing == false and Key.KeyCode == Enum.KeyCode.C then--This checks if the Player isn't Typing as well as if the C key has been pressed
		--YourCode
	end
end)

~UserOnly20Charcters, Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

1 comment

0

Thanks :D

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "x" then -- change the 'x'
-- do stuff
end)

2 comments

0

I strongly suggest that you shouldn't use KeyDown event as its Deprecated!

0

It's the 'basic' scripting, there's nothing wrong with it.

function keypress(UserInput, gameProcessedEvent)
if UserInput.KeyCode == Enum.KeyCode.R then
--YOUR CODE
game:GetService("UserInputService").InputBegan:connect(keypress)
end

Use UserInputService, avoid keydown since its deprecated.

1 comment

0

Do not use KeyDown it's a bad way to get key input.

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