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

Issue with the ROBLOX KeyBoard Input, no KeyUp Detection?

So I am basically making my own control script for the roblox character, and I am having an issue in the keyboard input, what I am trying to do is when the player's "W" key goes down, make the player's characters torso go forward until the "W" key goes up. I am having trouble finding when the "W" key goes up, and I am pretty frustrated as roblox does not seem to have any method or function able to find when a key goes up. Here is the local control script so far:

local r 	= game:GetService("ReplicatedStorage"):WaitForChild("Control");
local uis 	= game:GetService("UserInputService");
local cas 	= game:GetService("ContextActionService");
uis.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		r:FireServer("W");
	end
end

When r (the remote event) fires the server the "W" string, the server script will make the character move forward according to the torso's lookVector. This works great, but it only moves forward one time when the w key is down. I am trying to get the character to continue moving forward while the w key is down, and halt movement when the w key goes up. Any help would be appreciated a lot. Thanks

1 answer

Are you looking for InputEnded ???

Example:

game:GetService("UserInputService").InputEnded:connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W then
		--put ur stuff here
	end
end)

1 comment

0

no, because UserInputService does not register a key being held down as continuous input. Thankfully I found out the GetKeysPressed() function, which helps a lot. Thanks for trying to help tho!

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