The stamina system dosen't work?

i dont know why but this code dosent work for some reason

local staminaFrame = script.Parent
local maxStamina = 500
local minStamina = 0
local staminaChange = 1
local changeInterval = 0.05

local function reduceStamina()
	local newStamina = math.max(staminaFrame.Size.X.Scale - staminaChange, minStamina)
	staminaFrame.Size = UDim2.new(newStamina, 0, staminaFrame.Size.Y.Scale, 0)
end

local function increaseStamina()
	local newStamina = math.min(staminaFrame.Size.X.Scale + staminaChange, maxStamina)
	staminaFrame.Size = UDim2.new(newStamina, 0, staminaFrame.Size.Y.Scale, 0)
end

local function onInputBegan(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.LeftShift then
		while wait(changeInterval) and inputObject.UserInputState == Enum.UserInputState.Begin do
			reduceStamina()
		end
	end
end

local function onInputEnded(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.LeftShift then
		while wait(changeInterval) and inputObject.UserInputState == Enum.UserInputState.End do
			increaseStamina()
		end
	end
end

game.Players.LocalPlayer:GetMouse().KeyDown:connect(onInputBegan)
game.Players.LocalPlayer:GetMouse().KeyUp:connect(onInputEnded)

(Code was made by AI)

1 Like

Have you tried using the output to detect the problem?

nothing in the output for some reason

the if in the input began
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
is in the function , maybe thats the issue

theres nothing showing up because ur probably not actually activating the function

you need to also start the function from the outside

thank you for your help, i made this code using AI and it was stupid lol

yea no problemo :sunglasses: i am happy to help

1 Like

better use local mouse = game.Players:GetMouse() in the start of the code
and put wait(1) for player fully load before script will runs, sometimes will issues with this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.