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

Keydown then GUI is Visible?

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)

3 comments

0

Is it a LocalScript?

0

Yes

3

Try setting the variable 'Player' to: game.Players.LocalPlayer

2 answers

✓ Accepted answer

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)

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