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

Help with KeyDown?

Can anyone tell me why this script won't work? Output show's no error's. I am trying to make a Custom-Chat GUI, But this KeyDown thing won't work.

wait(1)

-- Variables
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Text = script.Parent.TextFrame.TextBox

-- Main Script
Mouse.KeyDown:connect(function(key)
	if key == Enum.KeyCode.Slash then
		Text:CaptureFocus()
	end
end)

1 comment

1 answer

✓ Accepted answer

Problem Roblox locks backslash as its used in their own functions this is able from this script below. Solution

-- Variables
local Player = game.Players.LocalPlayer
repeat() wait until Player.Character
local Mouse = Player:GetMouse()
local Text = script.Parent.TextFrame.TextBox

-- Main Script
game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Slash then
        Text:CaptureFocus()
    end
end

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