Here's my script;

local player = game.Players.LocalPlayer
local staminabar = script.Parent:WaitForChild("StaminaBar")
local staminatext = script.Parent.StaminaBar:WaitForChild("StaminaText")

player.CharacterAdded:connect(function()
	local currentstamina = player:WaitForChild("Status"):WaitForChild("CurrentStamina")
	local maxstamina = player:WaitForChild("Status"):WaitForChild("MaxStamina")
	staminatext.Text = "Stamina: "..currentstamina.Value.." / "..maxstamina.Value
end)

player.CharacterAdded:connect(function()
	local currentstamina = player:WaitForChild("Status"):WaitForChild("CurrentStamina")
	local maxstamina = player:WaitForChild("Status"):WaitForChild("MaxStamina")
	currentstamina.Changed:connect(function(Value)
		local staminapercentage = currentstamina.Value / maxstamina,Value
		staminabar.Size = UDim2.new(staminapercentage, 0, 1, 0)
		staminatext.Text = "Stamina: "..currentstamina.Value.." / "..maxstamina.Value
			while i <= maxstamina.Value do
   			 i = currentstamina.Value + 1
    		wait(1)
		end
	end)
end)

There are no errors,

This is the place that doesn't work;

			while i <= maxstamina.Value do
   			 i = currentstamina.Value + 1
    		wait(1)
		end

Please help.

3 comments

0

Are you sure the CharacterAdded functions trigger?

0

isn't character added when you join?

0

CharacterAdded doesn't work when you use it in a localscript the first time, as the script will get loaded after the character gets added