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

How to use the keyboard input to change tools?

Asked by 8 years ago

So i'm trying to change the tools with two keys, maybe Q and E but i don't know how to do it. I know it has something to do with the keyboard input and local scripts. I would appreciate any help.

1 answer

Log in to vote
1
Answered by 8 years ago

This is a little script I made that should work. It works on a ServerScript and LocalScript.

local uis = game:GetService("UserInputService") -- Get the UserInputService.

uis.InputBegan:connect(function(inputObject) -- Function fires when any input from your device is recieved, where inputObject is an Instance with a Child containing information about the key, button or anything else.
    if inputObject.KeyCode == Enum.KeyCode.E then -- If statement that checks if the KeyCode is E
        print("E was pressed!") -- Print success.
    end
end)

Read more here: http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan

Ad

Answer this question