!NEED HELP! how to tween stamina bar

  1. What do you want to achieve? I want make a stamina bar which tween on both sides. Example, mostly stamina has one side to decrease or to increase but instead I want do both side to decrease or to increase. also when when on low will turn to red. Also will appear when use shift. but if dont use shift then stamina bar wont appear.

  2. What is the issue? stamina bar only decrease on one side. wont change to red when on low. also I dont know how to make stamina to show up when use shift.

  3. What solutions have you tried so far? I been search tutorials and non of these is match what I look for. Mostly, these is only show stamina bar decrease on one side and not show how make change color or show up when use shift.

!!REMINDER!! I’m beginner, I dont know lot about script field. so Im completely lack in these.

3 Likes

If you want it to tween from both sides, you need to tween the position at the same time to make it look like its shrinking from each side

1 Like

Anchor the bar in middle of a frame and set the size so it stays in the middle

AnchorPoint = 0.5, 0
Position = (0.5, 0), (0, 0)

https://gyazo.com/8fe6e40c81b7713f2362ff8a2d50d7ce

2 Likes

i have a script just like this! its really easy if you use gui! ill get the script for you, best part: it does not use tween! its lag free and compact to use!
7

local display = script.Parent
local head = script.Parent.Parent:WaitForChild("Head")
local label = display.BillboardGui.HEALTH
local frame = display.BillboardGui.bg.Frame

local Hum = script.Parent.Parent:WaitForChild("Humanoid")
Hum.HealthChanged:Connect(function()
	label.Text = Hum.Health
	local tmp = (Hum.Health / Hum.MaxHealth * 200)
	frame.Size     = UDim2.new(0, tmp, 0, 50)
	frame.Position = UDim2.new(0, 100 - (tmp / 2), 0, 0)
end)

if you need anything related to this just ask! if you want me to personally install this just reply! (costs 5 robux bc i have other work to do)

3 Likes

I made a script and interface for you and everyone who needs a similar model based on your description.

359x72

70%from 100% to 20%

Group 4

15%from 20% to 0%

You can get it here. Look at the script I wrote and customize it for yourself.
https://create.roblox.com/store/asset/16973558793/Stamina?viewFromStudio=true&keyword=&searchId=C44DD505-0115-4586-9C1C-7A339A8F068F

Or you can get the model file directly.

Stamina.rbxm (7,5 КБ)

6 Likes

Okay, so you will be needing a stamina bar ui for this script. With a “bar frame object”

Here’s the script I made for it, hope it helps:

local Ui = script.Parent
local MAX_STAMINA = 100
local CURRENT_STAMINA = MAX_STAMINA
local Uis = game:GetService("UserInputService")
local IsRunning = false
local Bar --Path to the bar

if not game:IsLoaded() then repeat task.wait() until game:IsLoaded() end

Uis.InputBegan:Connect(function()
	if Uis:IsKeyDown(Enum.KeyCode.LeftShift) then
		if CURRENT_STAMINA == 0 then return end
		IsRunning = true

		while IsRunning do
			task.wait(.25)

			CURRENT_STAMINA -= 1

			math.clamp(CURRENT_STAMINA, 0, MAX_STAMINA)

			if CURRENT_STAMINA == 0 then
				IsRunning = false 
				return
			end
		end
	end
end)

Uis.InputEnded:Connect(function(input,gpe)
	if gpe then return end

	if input.KeyCode == Enum.KeyCode.LeftShift then
		IsRunning = false

		while not IsRunning do
			task.wait()

			if CURRENT_STAMINA < MAX_STAMINA then
				task.wait(.25)
				CURRENT_STAMINA += 1

				math.clamp(CURRENT_STAMINA, 0, MAX_STAMINA)

				if CURRENT_STAMINA == MAX_STAMINA then
					return
				end
			end

		end
	end
end)

game:GetService("RunService").RenderStepped:Connect(function(dt)
	Bar.Size = UDim2.new(0,CURRENT_STAMINA * (374/MAX_STAMINA),0,46) --374 was the max size of the bar I took replace it with your bar size and 46 same but for the (yOffset)
end)


2 Likes

I think you have misunderstood his needs, you used a Healthbar, he wanted a stamina bar.

But still good script :wink: @1gotba_nned0

1 Like

you guys are so helpfull!!! thank you guys for helps!! I definitely try it!

its truly amazing model, however if keep hold shift to 0 then auto regen it. which I dont want that. I only want to regen is by release shift then will regen.

I tried your script, and kinda not working. I may did do something wrong.

Thank you!
To solve your problem, find a similar piece of code in the script and replace it with this one.

UserInputService.InputBegan:Connect(function(Input: InputObject, Event: boolean)
	if Input.KeyCode == Enum.KeyCode.LeftShift and StaminaLeft > 0 and Humanoid.MoveDirection ~= Vector3.zero then
		CanRegen = false

		TweenService:Create(Humanoid, TweenInfo.new(.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
			WalkSpeed = 22
		}):Play()

		local LoopOver: boolean = false

		-- Connection
		local Connection: RBXScriptConnection
		Connection = Input:GetPropertyChangedSignal("UserInputState"):Once(function()
			LoopOver = true
		end)

		-- Cycle
		repeat
			StaminaLeft -= CalcA
			task.wait()
		until LoopOver or StaminaLeft < 0
		
		TweenService:Create(Humanoid, TweenInfo.new(.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
			WalkSpeed = 16
		}):Play()
		
		if not LoopOver then
			repeat
				task.wait()
			until LoopOver
		end

		-- Check
		if Connection.Connected then
			Connection:Disconnect()
		end

		CanRegen = true
	end
end)
2 Likes

Its working pretty great! Thank you so much!!!

1 Like

Probably because I didn’t update the walkSpeed, but it’s already solved, so nevermind.

1 Like

But still, thank you for try help! Im truly grateful that you trying to help!

thanks i guess, I know mine is for a healthbar but I think personally that doesnt matter as much, the code still used gui and a script that was easily changable with one good look. still thanks… i guess?

1 Like

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