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

Keydown then GUI is Visible?

Asked by 9 years ago

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)
0
Is it a LocalScript? M39a9am3R 3210 — 9y
0
Yes GianniKun 40 — 9y
3
Try setting the variable 'Player' to: game.Players.LocalPlayer thehawkhunter 45 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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)
Ad
Log in to vote
0
Answered by 9 years ago

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)

Answer this question