When the key b is pressed I want the Gui to become visible but its not working.
Script is in Backpack
local Player = script.Parent.Parent local Mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "b" then Player.PlayerGui.Guide.Frame.Visible = true end end Mouse.KeyDown:connect(onKeyDown)
Make sure the LocalScript is in StarterPack and that the Frame is invisible, otherwise it will not work.
This should work:
local Player = game.Players.LocalPlayer --Since this is a localscript, use LocalPlayer instead local Mouse = Player:GetMouse() function onKeyDown(key) local key = key:lower() -- I made this into a local variable if key == "b" then Player.PlayerGui.Guide.Frame.Visible = true end end Mouse.KeyDown:connect(onKeyDown)
Hmmm.. Try this method instead (It must be in the LocalScript)
local mouse = game:GetService('Players').LocalPlayer:GetMouse() mouse.KeyDown:connect(function (key) if string.byte(key) == 98 then --(Dec>98 = "b") Refer to the ASCII table. You can search it in google. You must use lowercase characters. Player.PlayerGui.Guide.Frame.Visible = true end end)