Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Stamina frame doesn't resize?

--{{hi}}--
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Gui = Player.PlayerGui.Stam
local MaxStamina = Gui.Frame.MaxStamina -- max size = {0.945, 0},{0.542, 0}
local Stamina = Gui.Frame.Stamina -- it's size is {0.945, 0},{0.542, 0}
local UIS1 = game:GetService("UserInputService")
local on = false
UIS1.InputBegan:connect(function(UIS)
	if UIS.KeyCode == Enum.KeyCode.R then
		on = true
		repeat 
		wait()
		Stamina.Size.X = Stamina.Size.X - UDim2.new(0.1,0)
		until on == false and Stamina.Size == UDim2.new(0.0,0,0.542,0)
		end
end)

UIS1.InputEnded:connect(function(UIS)
	if UIS.KeyCode == Enum.KeyCode.R then
		on = false
		repeat 
		wait()
		Stamina.Size.X = Stamina.Size.X + UDim2.new(0.1,0)
		until on == true and Stamina.Size == UDim2.new(0.945,0,0.542,0)
		end
end)

1 comment

0

Use tweening for stuff like this. It saves a lot of time.

1 answer

✓ Accepted answer

I'm not sure if you know about TweenSize.

It's very useful, as it will reduce your lines of code as well as your hideous repeat loops.

As for stamina, I think it would be better to keep number values instead of the gui size.

Here is a example.

local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui.Stam
local StaminaBar = Gui.Frame.Stamina
local MaxStamina = 60
local Stamina = 60

local function UpdateGUI()
	StaminaBar:TweenSize(UDim2.new(Stamina/MaxStamina,0,1,0),"Out","Linear",.25)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.