Script Broken Please Help

Hi so i have this script here and it was working before but now its not can anybody identify the problem

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local UserInputService = game:GetService("UserInputService")

local Stamina = 100
local Running = false
local SprintSpeed = 30
local WalkSpeed = 16 

script.Parent.PlayerName.Text = Player.Name
script.Parent.PlayerThumb.Image = "rbxthumb://type=AvatarHeadShot&id=" ..Player.UserId.. "&w=420&h=420"

Character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):connect(function()
	script.Parent.HealthBar.Bar.Size = UDim2.new(math.floor(Character.Humanoid.Health) / 100, 0, 1, 0)
end)

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Running = true
		Character.Humanoid.WalkSpeed = SprintSpeed
		while Stamina > 0 and Running do
			Stamina -= 0.5
			--print(Stamina)
			if Stamina == 0 then
				script.Parent.StaminaBar.Bar.Visible = false
			else
				script.Parent.StaminaBar.Bar:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
			end
			wait()
			if Stamina == 0 then
				Character.Humanoid.WalkSpeed = WalkSpeed
			end
		end
	end 
end)

UserInputService.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Running = false
		Character.Humanoid.WalkSpeed = WalkSpeed
		while Stamina < 100 and not Running do
			script.Parent.StaminaBar.Bar.Visible = true
			Stamina += 1
			--print(Stamina)
			script.Parent.StaminaBar.Bar:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
			wait()
			if Stamina == 0 then
				Character.Humanoid.WalkSpeed = WalkSpeed
			end
		end
	end
end)
2 Likes

what is the problem?

character limit

so its supposed to make a ui bar shrink like a health bar but its not doing that

what does the stamina ui look like? is it still? is it increasing?

health and stamina ui are not shrinking

Screenshot 2023-08-30 185744

--print(Stamina)
I notice you have this line of code in the InputBegan and InputEnded. Is the stamina increasing but the gui is not increasing?

noon the stamina ui doesnt decrease

i was able to fix health but stamina still does not work

try adding print statements after some if statements to see how far the code gets. if it fails one of theprint statements, then you know where the problem is. can you show your updated code after the fix?

Infinite yield possible on ‘Players.Diam0ndzOnYT.PlayerGui.StaminaAndHealthBar.Frame.Player.ViewportFrame.WorldModel.Diam0ndzOnYT.HumanoidRootPart:WaitForChild(“Running”)’

i meant show the updated code too

which script is it coming from? can you put the code of that script here?

ok so there are 2 script

local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local MouseInDisplay, HoldInDisplay = false, false

local currentX

-- Character Display
local VPFcam = Instance.new("Camera"); VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam

repeat wait(.1) until game:IsLoaded()

char.Archivable = true

local ClonedChar = char:Clone()

ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5),Vector3.new(0,0,0)))

-- Turning Feature
uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		if MouseInDisplay == true then
			HoldInDisplay = true
			currentX = nil
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		HoldInDisplay = false
	end
end)

script.Parent.ViewportFrame.MouseMoved:Connect(function(X,Y)

	if HoldInDisplay == false then return end

	if currentX then ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*.025),0) end

	currentX = X
end)

script.Parent.ViewportFrame.MouseEnter:Connect(function() MouseInDisplay = true end)
script.Parent.ViewportFrame.MouseLeave:Connect(function() MouseInDisplay = false end)

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local UserInputService = game:GetService(“UserInputService”)

local Stamina = 100
local Running = false
local SprintSpeed = 30
local WalkSpeed = 16

– Make sure the UI elements exist before referencing them
local StaminaBar = script.Parent.StaminaBar.Bar
local HealthBar = script.Parent.HealthBar.Bar

– Set initial UI sizes
StaminaBar.Size = UDim2.new(1, 0, 1, 0)
HealthBar.Size = UDim2.new(1, 0, 1, 0)

– Update the health bar when the Humanoid’s Health changes
Character:WaitForChild(“Humanoid”).Changed:Connect(function(property)
if property == “Health” then
HealthBar.Size = UDim2.new(Character.Humanoid.Health / 100, 0, 1, 0)
end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
– Make sure the input isn’t processed by other UI/game systems
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.LeftShift then
Running = true
Character.Humanoid.WalkSpeed = SprintSpeed
end
end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.LeftShift then
Running = false
Character.Humanoid.WalkSpeed = WalkSpeed
end
end
end)

– Stamina regeneration loop
while true do
if not Running and Stamina < 100 then
Stamina = math.min(Stamina + 0.5, 100)
StaminaBar:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
end
wait(0.1) – Adjust the wait time as needed
end

replace HumanoidRootPart:WaitForChild("Running") and replace with Humanoid.Running instead

ok i will try that thanks char limit

i cant find it where do you see this

The only reason this would happen is because HumanoidRootPart.Running does not exist. Perhaps you’re looking for Humanoid.Running?

i dont see it can you try to find it?

how did you get this error?