Stamina Bar Text Not Working

Hello everyone! I’m trying to create a Stamina Bar GUI that uses a text label to tell you how much you have left, but I can’t seem to get it to work. I’m new to ALL of this, so any help would be appreciated! Here’s my code and explorer.
image
image

local player = game.Players.LocalPlayer
local character = player.Character
local staminaText = script.Parent:WaitForChild("StaminaAmount")

local UserInputService = game:GetService("UserInputService")

local stamina = 100
local running = false

stamina = math.clamp(stamina, 0, 100)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		running = true
		character.Humanoid.WalkSpeed = 32
		while stamina > 0 and running do
			stamina = stamina - 1
			script.Parent.Overlay:TweenSize(UDim2.new(stamina / 100, 0, 1, 0), "In", "Sine", 0)
			wait()
			if stamina == 0 then
				character.Humanoid.WalkSpeed = 16
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		running = false
		character.Humanoid.WalkSpeed = 16
		while stamina < 100 and not running do
			stamina = stamina + 1
			script.Parent.Overlay:TweenSize(UDim2.new(stamina / 100, 0, 1, 0), "In", "Sine", 0)
			wait()
			if stamina == 0 then
				character.Humanoid.WalkSpeed = 16
			end
		end
	end
end)
function StaminaChanged(NewStamina)
	staminaText.Text = stamina
end

you didnt even use the StaminaChanged function down the script

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local staminaText = script.Parent:WaitForChild("StaminaAmount")

local UserInputService = game:GetService("UserInputService")

local stamina = 100
local running = false

function StaminaChanged()
	script.Parent.Overlay:TweenSize(UDim2.new(stamina / 100, 0, 1, 0), "In", "Sine", 0)
	staminaText.Text = stamina
end

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		running = true
		
		while stamina > 0 and running do
			character.Humanoid.WalkSpeed = 32
			stamina = stamina - 1
			
			StaminaChanged()
			
			wait()
		end
		
		character.Humanoid.WalkSpeed = 16
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		running = false
		character.Humanoid.WalkSpeed = 16
		
		while stamina < 100 and not running do
			stamina = stamina + 1
			
			StaminaChanged()

			wait()
		end
	end
end)

Yep, just saw that now. Works now, thanks!

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