Tweening gui issue

im trying to tween the purple bar so that it goes down, however as u can see int he video that is not the case, I’m not sure how to tween the bar so that it goes down rather then moving to the left.
image

local TW = game:GetService("TweenService")

local Player = game:GetService("Players").LocalPlayer 
local Character = Player.Character or Player.CharacterAdded:Wait() 
local Humanoid = Character:WaitForChild("Humanoid") 

local BusoHakiBar = script.Parent 

local function UpdateBusoHakibar() 
	local Haki = math.clamp(Character:GetAttribute("BusoHakiTime") / Character:GetAttribute("MaxBusoHakiTime"), 0, 1) 
	local info = TweenInfo.new(Character:GetAttribute("BusoHakiTime") / Character:GetAttribute("MaxBusoHakiTime"),Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) 
	TW:Create(script.Parent,info,{Size = UDim2.fromScale(Haki, 1)}):Play()
end


Character:GetAttributeChangedSignal("BusoHakiTime"):Connect(UpdateBusoHakibar)


You should use your frame’s anchorpoint property. Since you want it going down, you should make your anchor point 0.5, 1. Although, by configuring your anchorpoint, you’ll have to adjust your frame position again.

its much better now however the bar contracts rather then going down, like how would I make it so that it goes from the top and reduces to the bottom rather then from reducing from both sides and meeting at the middle.

Could you perhaps show me how your GUI is constructed, along with the properties of the GUI and the frame?

(Do not mind this anymore)

Oh wait… Your frame rotation is 90? Try doing anchor point 1, 0.5 instead.

Now, its back to the way it started originally

image

If that’s so, I suggest you to use rotation 0 instead.

Anchorpoint → 0.5, 1

In your code, you should also change the following:

-- Affects x axis
TW:Create(script.Parent,info,{Size = UDim2.fromScale(Haki, 1)}):Play()

to:

-- Now affects y axis
TW:Create(script.Parent,info,{Size = UDim2.fromScale(1, Haki)}):Play()

i changed rotation to 90 and set anchor point 0.5,1 and changed script

I think that this issue is being caused by how your UI is structured, rather than an issue with your code. I recommend doing something like this (arrows indicate that it’s a child):

Base Frame (only rotate and position this frame)
→ Purple bar

→ ImageLabel that contains the stripes (make sure that its ZIndex is higher than the one being used by the purple bar)
->-> TextLabel

You also won’t need to worry about the anchor points of any GUI other than the base frame

@rxnwei has posted a solution before me, but I’m going to post this place file as I wrote it up but went to eat breakfast. Hope it helps too!

BusoHakiTime Bar.rbxl (58.4 KB)

Make note of the properties on the Frame parent (and its parent) of the LocalScript. Like @JohhnyLegoKing said, it’s more likely that your UI structure/properties have led to some issues with your scaling than has the current tweening.

1 Like

If the changes were set accordingly, it may be a problem with the setting of the gui itself instead… Try using @JohhnyLegoKing 's suggestion. Although, I’m pretty sure the purple bar should also have an anchorpoint since it’s the one supposed to be moving, and not the base frame. But pretty much, everything else he said is correct.

1 Like

A little hack I like to use in my progress bars is putting a UIListLayout in it, locking the bar into place.

From there, just tween the Y scale size of the bar.

From what I’ve read, you don’t need to (and shouldn’t) rotate anything. Using AnchorPoint is also a valid option but my way is simpler.

2 Likes

This is actually a genius way to use UIListLayout. :eyes:

Learned something new today lol

This is smart af

I would use AnchorPoint properties when there are multiple objects that need to be adjusted when the health meter changes. I haven’t used UIListLayouts recently so I’m just wondering: have you found a better way to make a progress bar with multiple changing features? Whether that be a “buffer” color between what is lost and what the current bar is at or overlaying two different stats in one bar.

guys… i tried for a couple of days, but nothing seems to work, its clear that it is my gui formating.
here is the surface GUI, can someone fix my GUI formatting? (would be nice if the size was the same
SurfaceGui.rbxm (10.2 KB)

I checked the place file that you’ve provided, and I noticed a very important detail: You’re using a BillboardGui, not a ScreenGui. BillboardGuis scale their children in a different way than ScreenGuis, as it’s dependent on the stud size of its adornee:

The quote above was taken from this docs article: BillboardGui | Documentation - Roblox Creator Hub

I’m pretty confident that using a ScreenGui would solve most of the problems that you’re experiencing

Are ScreenGuis able to be put on 3d parts?

No, but you can make the GUI follow the player using the current camera’s WorldToScreenPoint/WorldToViewportPoint method:

-- Needs to be a LocalScript that's a direct child of the ScreenGui
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local OFFSET = Vector3.new(2, 0, 0) -- The offset, in studs, for your GUI relative to the player's root part

local camera = Workspace.CurrentCamera or Workspace:WaitForChild("Camera")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character.PrimaryPart or character:WaitForChild("HumanoidRootPart")

local gui = script.Parent
local base = gui:WaitForChild("Base") -- Make sure that the name matches the one you're using, otherwise an error will occur


local function onHeartbeat()
	local rootPosition = rootPart.Position + OFFSET
	local screenPoint = camera:WorldToScreenPoint(rootPosition) -- You'll need to use WorldToViewportPoint if you're ignoring the topbar offset

	base.Position = UDim2.fromOffset(screenPoint.X, screenPoint.Y)
end

RunService.Heartbeat:Connect(onHeartbeat)