Well, basically the following adds a number from the numberValue for a progress bar. The script works by holding down a defined key and releasing the key starts subtracting the value from the numberValue. The problem here is that the inputBegan function keeps executing despite releasing it.
local UserInputService = game:GetService("UserInputService")
local numValue = script.Parent:FindFirstChild("numValue")
local Enabled = false
UserInputService.InputBegan:Connect(function(key)
if (key.KeyCode == Enum.KeyCode.E) then
if Enabled == false then
while Enabled == false and wait(0.01) do
numValue.Value = numValue.Value + 1
end
end
end
end)
UserInputService.InputEnded:Connect(function(key) -- Detect when key is lifted
if (key.KeyCode == Enum.KeyCode.E) then
Enabled = false
while Enabled == true and wait(0.01) do
numValue.Value = numValue.Value - 1
end
end
end)