I would like to change this script (that I found) to be for while the player holds the key down, then once it lets go, it overrides the function. Anyone know how I could change it to work? I tried changing line 5’s first “KeyCode” to “KeyHeld”, but I just get an output of “Keyheld is not a valid member of InputObject “InputObject””
You’ll need to use the InputEnded to do this, example:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
game.Lighting.Blur.Size = 50
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
game.Lighting.Blur.Size = 0 -- Reset blur size
end
end)
To ensure the blur effect doesn’t interfere with gameplay when players are using the ‘C’ key for typing in game interfaces like chat, it’s prudent to include a condition that checks the context of the key press. The parameter gameProcessedEvent in the InputBegan and InputEnded events serves this exact purpose. If this parameter is true , it signifies that the key press was captured by a UI element, such as a chat box.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
game.Lighting.Blur.Size = 50
end
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
game.Lighting.Blur.Size = 0
end
end
end)