stamina = 100 local user = game:GetService("UserInputService") local key = Enum.KeyCode.Q local keyheld = false function OnInput(inputObject, gameprocessedevent) if inputObject.UserInputState == Enum.UserInputState.Begin then if inputObject.KeyCode == key and keyheld == false then keyheld = true if keyheld == true then print (stamina) if inputObject.UserInputState == Enum.UserInputState.End then keyheld = false if keyheld == true then stamina = stamina - 10 if stamina < 100 then wait(10) do stamina = stamina + 10 if stamina == 100 then end user.InputBegan:Connect(OnInput) user.InputEnded:Connect(OnInput) end end end end end end end end
When i press Q the script dosent print the stamina value what am i doing wrong?
I cleaned up your code a little and took some stuff out. You will have to re-add and adjust yourself for I do not know exactly what you are trying to do.
You can learn about RunService
here
and more about UserInputService
here
stamina = 100 local user = game:GetService("UserInputService") local run = game:GetService("RunService") local key = Enum.KeyCode.Q local keyheld = false function BeginInput(inputObject,gameprocessedevent) if inputObject.UserInputState == Enum.UserInputState.Begin then if inputObject.KeyCode == key then keyheld = true end end end function EndInput(inputObject, gameProcessedEvent) keyheld = false end local timer = 1 function KeyHeld() if keyheld then print(stamina) -- print(stamina) end end user.InputBegan:Connect(BeginInput) -- Connect function BeginInput user.InputEnded:Connect(EndInput) -- Connect function EndInput run:BindToRenderStep("KeyHeld", 1, KeyHeld) -- Connect function KeyHeld (Case Sensitive) to RenderStep