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.
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.
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.
This is really helpful! But how would I add all the body parts onto the body and stuff xD
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
use userinputservice