How can I do this?

Hey guys. I’m having some UI problems. Take a look at this screenshot.
Screenshot 2023-09-10 173847
Let me explain what you’re looking at here. The yellow bar is the HP, the green bar is poison, and the red bar is the background/how much HP is missing. My goal is if the player touches poison, the green bar will cover their HP, but only by how much poison will take away their health. Is there a way I can achieve this?

I would put the Poison frame inside of the HPBar frame and set both anchor points to 0.5,0.5. Then to get the poison bar on the left side of the HPBar, the X Scale value for the poison bar’s position should be half of the X scale value of the poison bar’s size + 1.

local poisonBar = script.Parent.HPBar.PoisonBar

poisonBar:GetPropertyChangedSignal("Size"):Connect(function()
	poisonBar.Position = UDim2.fromScale(poisonBar.Size.X.Scale/2 + 1, poisonBar.Position.Y.Scale)
end)

This code worked for me, so hope this works for you.

1 Like

thanks a lot! i’m trying it out now. I’ll get back to you once i have :smiley:

1 Like

I might have fixed it a little. I’m going to run a few more tests.

I assumed your original anchor points were 0.5,0.5, but if they were 0,0, this is even simpler. You don’t need the script for that anymore, and just set the position of the Poison bar to (1,0,0,0).

1 Like

Updated the post. I hope it makes more sense now. Sorry for any previous confusion.