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

How do I detect the users input then stop detecting it?

I am creating a shop gui that will open and close when the players chosen key is pressed. I found out how to find the key, but not stop detecting the key after a key is pressed for the first time. Heres my code:

but = script.Parent
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local function inputDetecter()
	repeat UIS.InputBegan:Connect(function(key, gp)
		print(key.KeyCode)
		but.KeyVal = tostring(key.KeyCode)
	end)
	until mouse.KeyDown
end
	

but.MouseButton1Click:Connect(function()
	inputDetecter()
end)

1 answer

If you want to detect when the player releases a key then try

UIS.InputEnded:Connect(function(key, gp)
	print(key.KeyCode.. " was released!")
end)

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