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

How do I make a keybind event?

Asked by 6 years ago

I just started working on a Hide and Seek project but I want to make it different. I want to make it so the when you hold down "E", it allows you hide under the bed or even in a wardrobe and while you are hidden in that area your character becomes invisible until you move away from the hiding place.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

To process user input, you should use the UserInputService.InputBegan event client-side, like so:

local Services = {
    UserInput = game:GetService("UserInputService")
}

Services.UserInput.InputBegan:Connect(function(InputObject, GameProcessedEvent)
    if GameProcessedEvent then
        return
    end

    if InputObject.KeyCode ~= Enum.KeyCode.E then
        return
    end

    -- The user pressed the 'e' key, and the input isn't handled by Roblox.
end)

We define a second parameter for our event listener, GameProcessedEvent. This will be a boolean value that is false when Roblox is not handling the user input, and true if it is (such as if the player is typing in chat the word "hello", we don't want to run our code!

The rest would be up to you. To make the character invisible, you can set the BasePart.Transparency property of the player's character's body parts.

Ad

Answer this question