How can I break this while true do script, so that once I let go of my C key, it will automatically stop the Blur value from increasing, and stop it at 0?
Here is my script:
local UIS = game:GetService(“UserInputService”)
local dogs = 0
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
print("Key is pressed/Held")
dogs = 0
while true do
game.Lighting.Blur.Size = dogs
dogs = dogs + 1
wait(0.1)
if dogs == 50 then
break
end
end
end
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
print("Key has been Released")
game.Lighting.Blur.Size = 0
end
end
end)
Here is a quick video of what I am talking about; Pay attention to the output, as when I hold the key, there is a print for it, as well as when I let go of it. There is also the amount of Blur in the right.
You can declare an outside boolean variable that defaults to false, and within the InputBegan if statement where ‘input.KeyCode == Enum.KeyCode.C’, you can set the boolean to true, and change the while loop to `while “variable name” then’, and in the InputEnded if statement where ‘input.KeyCode == Enum.KeyCode.C’, you can do “variable name” = false.
Might also want to set blur size to 0 if the “variable name” is false after the while loop too incase the blur changes again before the while loop stops
Right. Here’s the script. I’ve had the issue that the BoolValue is not a member of Workspace, but it is in workspace.
local UIS = game:GetService("UserInputService")
local dogs = 0
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
print("Key is pressed/Held")
game.Workspace.Dog = true
dogs = 0
while game.Workspace.BoolValue.Dog == true do
game.Lighting.Blur.Size = dogs
dogs = dogs + 1
wait(0.1)
if dogs == 50 then
break
end
end
end
end
end)
if game.Workspace.Dog == false then
game.Lighting.Blur.Size = 0
end
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.C then
print("Key has been Released")
game.Workspace.Dog = false
game.Lighting.Blur.Size = 0
end
end
end)