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

How come this simple script won't function?

Asked by 9 years ago

I just want the gui to appear when I press "c" This is in a local script.

player = game.Players.LocalPlayer

function onKeyDown(key)
    key:lower()
    if key == "c" then
        player.PlayerGui.Interface.Statistics.Visible = true
    end
end

2 answers

Log in to vote
0
Answered by
Hero_ic 502 Moderation Voter
9 years ago

You should be using user input service with everything you do that relates to that.

game:GetService("UserInputService").InputBegan:connect(function(input,proc) --we get the userinput service. we need proc to start it from activating while chatting
    if input.KeyCode == Enum.KeyCode.C then
        --STUFF HERE
    end
end)

--Also you can change input began to input end for ending inputs.

if this helped your welcome :D ~KIHeros (oh and please (upvote and) accept :P)

Ad
Log in to vote
0
Answered by 9 years ago

The reason it didn't work:

You needed to call the function.

local player = game.Players.LocalPlayer
local mouse = p:GetMouse()
-- your func
mouse.KeyDown:connect(onKeyDown)
0
your answer works but KeyDown is depreciated so use UIS Hero_ic 502 — 9y
0
Ik, but I answered his question, not give him him a completely different event lol. TheDeadlyPanther 2460 — 9y

Answer this question