Hi, Im trying to make a loop that breaks when you press the key Z. But for some reason the method Im currently trying doesnt work, along with a few others I tried.
repeat Input = game.UserInputService.InputBegan:Wait() until Input == Enum.KeyCode.Z
local UserInputService = game:GetService("UserInputService")
local Pressed = false
UserInputService.InputBegan:Connect(function(key, gpe)
if gpe == false then
if key.KeyCode.Name == "Z" then
Pressed = true
end
end
end)
while true do
if Pressed == true then
break
end
task.wait()
end
Yeah, if we’re talking about detecting when the Z is pressed, they could just do the following:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode == Enum.KeyCode.Z then
-- do whatever here
end
end)