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

How to insert this Special User Input key?

Asked by 10 years ago

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

Log in to vote
-1
Answered by
Lacryma 548 Moderation Voter
10 years ago

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.

0
How would I use "userinputservice" ? Orlando777 315 — 10y
0
But what if you wanted to replace / with 1? what do I write instead of "Enum.KeyCode.Slash"? Orlando777 315 — 10y
0
Enum.KeyCode.One Lacryma 548 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

wheres the

local Player =  game.Players.LocalPlayer?
0
I already have that, read the script, it says not the whole script is there. Orlando777 315 — 10y
0
I know. digitalzer3 123 — 10y

Answer this question