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

How do i detect if a key is being held?

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago
Edited 6 years ago

How would i detect if a key is being help? For example : lets say you hold the E button to charge something to make it bigger and if you let go at any moment it fires at that moment. Like if you hold it for the max seconds you get a bigger ki blast, and if you don't you get different sized blast's depending on how long you held the E button.

I was thinking of doing this :

local UIS = game:GetService("UserInputService")
keyHeld = game.workspace.Part.Size
keyCharge = false

UIS.InputBegan:Connect(function(Input)
local KeyCode = Input.KeyCode

if KeyCode == Enum.KeyCode.G and keyCharge == false then
keyCharge = true
print('started')
end
end)

UIS.InputEnded:Connect(function(Input)
    local KeyCode = Input.KeyCode

    if KeyCode == Enum.KeyCode.G and keyCharge == true then
        keyCharge = false
        print('ended')
    end
end)

while keyCharge == true do
wait(0.1)
keyHeld.Size = keyHeld.Size +Vector3.new(1, 1, 1)
--game.workspace.Part.Size = game. workspace.Part.Size +Vector3.new(1, 1, 1)
end
0
Andddddddd whats your problem? hiimgoodpack 2009 — 6y
0
When the play holds the E button a part gets bigger and when released it stops oSyM8V3N 429 — 6y
0
First of all, add a wait to "while keyHeld" Then just add into your while loop "yourpart.Size = yourpart.Size + Vector3.new(1,1,1)" Draebrewop 114 — 6y
0
Still won't work, i updated the script with the current script right now oSyM8V3N 429 — 6y
0
nvm i got it working, thanks oSyM8V3N 429 — 6y

Answer this question