Tweening Problem

Hello. I’m having a problem where I have this really basic health script I’ve used this before but I can’t seem to figure out how to make it work the opposite! way. Right now it does this

Capture2

And I need it to do this when lowered
Capture

This is a really basic script and is very commonly used if you have any suggestions or ideas on how I can have it tween in the opposite direction that would be very much appreciated!
Heres the script I have.

Humanoid.HealthChanged:Connect(function(newHeath)
	local MaxHP = Humanoid.MaxHealth
		if MaxHP then
			if newHeath > 0 then
			script.Parent:TweenSize(UDim2.new(newHeath/MaxHP,0,1,0), "In", "Quad", .25)
		else
			script.Parent.Size = UDim2.new(0,0,1,0)
			
			end
		end
end)

Answered xD Change anchor of the X value

1 Like

You can shorten your code like so:

Humanoid.HealthChanged:Connect(function(health)
	local Size = math.clamp(health / Humanoid.MaxHealth, 0, 1)
	
	script.Parent:TweenSize(UDim2.new(Size, 0, 1, 0), "In", "Quad", 0.25)
end)

To have it come from the right you want to set the green bar’s AnchorPoint to Vector2.new(1, 0.5) and you want to set its Position to UDim2.new(1, 0, 0.5, 0).

1 Like