Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pressing a key makes a part invisible?

So I have built a sniper rifle with bipod and everything. It's a tool but I want you to be able to Pull up and down the bipod when pressing F. I only want it so I can make one invisble and the other visible by pressing F.

Any help is very appreciated! //ItsRickGrimes

1 answer

✓ Accepted answer

You can use the UserInputService to detect if a key is being pressed, then you can make it do what you want. An example is shown here :

This is the InputBegan which detects when the key is pressed

local UIS = game:GetService("UserInputService")

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

if not gameProcessedEvent then

if KeyCode == Enum.KeyCode.F then
--do what you want here

end
end
end)

This is the InputEnded which detects when the key is released

local UIS = game:GetService("UserInputService")

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

if not gameProcessedEvent then

if KeyCode == Enum.KeyCode.F then
--do what you want here

end
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.