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

Creating a initiate type script?

Asked by 7 years ago
Edited 6 years ago

How would I make a script when a player pushes a specific key that they are then able to type in anything in a certain bar just like the chat? (ex: press / to type in chat)

I know how to do this:

player = game:GetService("Players").LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(k)
    key = k:lower()
    if key == "" then
        --etc
    end
end)

But I also wanted to specifically use unlisted key buttons that aren't numbers or letters such as '/', 'SHIFT', and etc. I think I saw a page to it but never knew what to do. (or maybe put that ID into the empty key quotations)

EDIT: This question has been answered.

1 answer

Log in to vote
2
Answered by 7 years ago

Part 1: UserInputService

Easy enough to learn is UserInputService, a better way get inputs than KeyDown (as it's deprecated):

game:GetService("UserInputService").InputBegan:connect(function(key,gameProcessed) -- key = InputObject, gameProcessed = bool (check to see if it's false to make sure the rest of the event isn't going when typing, for example)
    if key.KeyCode == Enum.KeyCode.Slash and gameProcessed == false then -- use autocomplete or the wiki to get the rest of the Enum.KeyCode keys
        -- code
    end
end)

Hopefully you can understand that. It will only work in LocalScripts, as far as I can tell.


Part 2: CaptureFocus

CaptureFocus is a method of TextBoxobjects, and is used to basically automatically select the TextBox you are calling it with:

textBox:CaptureFocus()

-- also note the following relevant things:

textBox:ReleaseFocus() -- opposite
textBox.Focused -- event
textBox.FocusLost -- opposite event

Hopefully I have given you what you wanted!

~TDP

0
This is very complex. Could you please link me some sources and stuff to help me understand this? I am a very basic scripter and rather understand almost intermediate topics and skills. AshRPG12 42 — 7y
0
UserInputService is a bit more complicated, but here are some links for both: http://wiki.roblox.com/index.php?title=API:Class/TextBox http://wiki.roblox.com/?title=API:Class/UserInputService If you have any questions, feel free to PM my main (EmeraldSlash). TheDeadlyPanther 2460 — 7y
0
I'm a little more experienced now, this is easy stuff to me. I forgot to accept your answer by the way. AshRPG12 42 — 6y
Ad

Answer this question