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

How can I make it so when I press a key I turn into a character or something?

Asked by 6 years ago

So basically what I want to make is a game like Ro-Ghoul, like how would I be able to make it so that when I click a key I turn into something, like how can I do that?

Well, thank you for reading.

0
use userinputservice User#20388 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Roblox has a service known as UserInputService which you can use for this sort of thing.

As stated on the Wiki article, you'll need to use a LocalScript when dealing with UserInputService.

Firstly, you'll need to 'get' the service. This is easy enough:

local userInputService = game:GetService("UserInputService")

UserInputService has an event called InputBegan, which can be used to fire some code when the client inputs something (a keyboard input, in your case). We can connect this event to a function like so:

userInputService.InputBegan:connect(function(item, gameProcessed)
    -- Code here
end)

You'll notice our function contains two arguments, 'item' and 'gameProcessed': 'item' returns the InputObject and 'gameProcessed' returns true or false depending on whether or not the game has processed the input (this will usually just return as 'true', so don't worry about it).

Currently the code in the function will run when the client makes any input, but if you wanted to connect it to only a single key we can use an if statement:

if item.KeyCode == Enum.KeyCode.E then
    -- Code here
end

This simply checks if what the player inputted is 'E' on the keyboard. If it is, the code is fired. Now to put it all together:

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:connect(function(item, gameProcessed)
    if item.KeyCode == Enum.KeyCode.E then
        -- Code here
    end
end)

Hope this helps.

0
This is really helpful! But how would I add all the body parts onto the body and stuff xD TheOnlySmarts 233 — 6y
Ad

Answer this question