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

Pressing a key makes a part invisible?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago

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)
Ad

Answer this question