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

How to use / as a keybyte?

Asked by 10 years ago

I am making a custom chat, which uses the same thing as kinda like roblox's chat but I disabled the coregui for chat. This works in studio but doesnt work in player so It must be something to do with the keybyte() == 47 anyone know how to enable it?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local able = false
local default = script.Default

function onkey(key)
    if key:byte() == 47
        then
        script.Parent:TweenSizeAndPosition(UDim2.new(1,0,.05,0), UDim2.new(0,0,.45,0), "Out", "Quad", .5, true)
        script.Parent.TextXAlignment = "Center"
        script.Parent:CaptureFocus()
        able = true
    end
end

function clear()
    script.Parent:TweenSizeAndPosition(UDim2.new(1,0,.025,0), UDim2.new(0,0,.975,0), "Out", "Quad", .5, true)
    script.Parent.TextXAlignment = "Left"
    able = false
    script.Parent.Text = default.Value
end

mouse.KeyDown:connect(onkey)
script.Parent.FocusLost:connect(clear)
0
Is this in a localscript? Sublimus 992 — 10y
0
mhm User#5978 25 — 10y
1
I'm pretty sure you can just a string for slash, like 'if key == "/" then end' Perci1 4988 — 10y
0
.... nope User#5978 25 — 10y
0
You can do ... if key == "/" then ... I've done it before, and it works just fine. Tkdriverx 514 — 10y

1 answer

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

I'd recommend using UserInputService instead of KeyDown as it will take in any human interaction (including keyboard presses) regardless of game state.

Also you don't have to mess around with key bytes (some keys have different byte codes in studio vs client, some have the same as others, etc) and can just use the KeyCode Enum instead.

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Slash then
        --code
    end
end
0
Thanks :) User#5978 25 — 10y
Ad

Answer this question