Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

3 comments

0

what do u do huh? fix it!

0

Fixed indentation.

0

I don't understand your question much. Can you explain what you are trying to do

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.