✓ Accepted answer
You are declaring and assigning to true a new local variable, ready, every time an input begins. Later in the listening function, when you attempt to check the value of this variable, it will be true.
To fix your script, you need to declare and initialise ready outside of the listening function. You should also be using RBXScriptSignal:Connect instead of RBXScriptSignal:connect, as the latter is deprecated. Along with this, I've made some other changes to your script that account for cases where the character may not exist, etc. and improve performance to a minor degree:
local user_input_service = game:GetService("UserInputService")
local is_ready = true
user_input_service.InputBegan:Connect(function(input, is_game_processed)
if input.KeyCode ~= Enum.KeyCode.G then
return
end
if is_game_processed then
return
end
if not is_ready then
return
end
local character = player.Character
if not character then
return
end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then
return
end
is_ready = false
humanoid.WalkSpeed = humanoid.WalkSpeed + 14
wait(3)
humanoid.WalkSpeed = humanoid.WalkSpeed - 14
wait(5)
is_ready = true
end)
2 comments
you should define ready out of inputbegan
put ready before you start your function