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

How to insert this Special User Input key?

I found this chunk of code in a script

--      -- CHatHotKey is '/'
--      GuiService:AddSpecialKey(Enum.SpecialKey.ChatHotkey)
--      GuiService.SpecialKeyPressed:connect(function(key) 
--          if key == Enum.SpecialKey.ChatHotkey then

So I want to add that "/" character instead of "e". As stupid as that sounds just replacing "/" for E wont work.

[MOUSE AND PLAYER ALREADY DEFINED]

--(Not the whole script, just 2 lines of it)
mouse.KeyDown:connect(function (key) -- Run function
    if key == "e" then

I tried this:

[MOUSE AND PLAYER ALREADY DEFINED]

--(Not the whole script, just 2 lines of it)
mouse.KeyDown:connect(function(Key)
    if key:byte() == 47 then -- 47 is the number code for "/"

But it only works in studio, not online. And yes, it's in a local script.

2 answers

✓ Accepted answer

The problem is that you never defined mouse. In a local script in startergui, it should be sorted as this:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:connect(function (key) 
local key = key:lower()
if key == "e" then
--do stuff
end
end)

If you would like to use "/", I recommend to use userinputservice instead.

4 comments

0

How would I use "userinputservice" ?

0

But what if you wanted to replace / with 1? what do I write instead of "Enum.KeyCode.Slash"?

0

Enum.KeyCode.One

wheres the

local Player =  game.Players.LocalPlayer?

2 comments

0

I already have that, read the script, it says not the whole script is there.

0

I know.

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