Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My script isnt printing the stamina value what do i do?

Asked by 5 years ago
Edited by TheeDeathCaster 5 years ago
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?

0
what do u do huh? fix it! HappyTimIsHim 652 — 5y
0
Fixed indentation. TheeDeathCaster 2368 — 5y
0
I don't understand your question much. Can you explain what you are trying to do RetroGalacticGamer 331 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
Ad

Answer this question