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

How to make a brick appear when a user holds in a key?

Asked by 4 years ago

So I'm gonna give some context here for you guys to help me. So basically I want to make my character have a shockwave appear around them when they hold in C, like a Naruto Chakra Charge. I have no idea where to start so i don't have any code to show, sorry. Also if you have time I'd love if you added comments to teach me a little. Thank you!!!

0
You will need to learn about UserInputService JesseSong 3916 — 4y
0
If you want to learn more about handling user input, the roblox developer page has some explanations on it: https://developer.roblox.com/en-us/api-reference/class/UserInputService DaysWeeksAndMonths 90 — 4y

2 answers

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

I just tried this and it worked fine

local inputService = game:GetService("UserInputService")
local isHoldingDownKey = false

inputService.InputBegan:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode.C then
            isHoldingDownKey = true
            -- shockwave appear code should go here
        end 
    end
end)


inputService.InputEnded:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.C then
            isHoldingDownKey = false
            -- the player isn't holding down the C key anymore.
        end
    end
end)

This needs to be in a LocalScript btw, and on the client (I put it in the StarterPack folder)

Hope this helps.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

First, since you want it to be for the client, then you'd have to use a LocalScript.

To check for the user input, you'd want to use the UserInputService.

Example:

local UserInputService = game:GetService("UserInputService")

--this will check for when the input begins
UserInputService.InputBegan:Connect(function(Input)
--we are using KeyCode since you want a key.
--this will check for when you hold down C
if Input.KeyCode == Enum.KeyCode.C then
--code
end
end)

--and when the input ends
UserInputService.InputEnded:Connect(function(Input)
--this will activate whenever you stop holding down C
if Input.KeyCode == Enum.KeyCode.C then
--code
end
end)

I would like to show you the rest but I'm quite busy at the moment.

So that's the basics covered.

if you want everyone to see that the client is charging, then you'd want to use a RemoteEvent with the function :FireServer() and it's callback which is .OnServerEvent.

When it comes to changing the transparency for a part, it should be obvious that you are going to be changing the property .Transparency to 0 for it to appear and 1 to disappear.

I hope I covered everything you needed the most.

Answer this question