Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

:CaptureFocus() without Key ?

Asked by 5 years ago
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)*

if key == "h" then
    script.Parent:CaptureFocus()
end

end)

but when i press "h" it send "h" on the textbox.

How do i make it so it doesn't send the "h" ?

1 answer

Log in to vote
1
Answered by 5 years ago

You need to put a wait before capturing focus, like so

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)*

if key == "h" then
    wait()
    script.Parent:CaptureFocus()
end

end)

However, you should indent and not use deprecated stuff, so use UserInputService like

game:GetService("UserInputService").InputBegan:Connect(function(key) --its only one letter bigger than keydown!
    if key.KeyCode == Enum.KeyCode.H then
        wait()
        script.Parent:CaptureFocus()
    end
end)

Hope this helps!

Ad

Answer this question