Need help understanding tween size

so i have managed to learn some tweensize, but i am still not sure what is happening here:


as you can see, it stops at that point even thought it should be completely gone. why is this happening?
script:

local progress = targetToDestory.Health.Value/targetToDestory.MaxHealth.Value
			value.TextLabel:TweenSize(
				UDim2.new(0.9*progress,0, 0, 30)
			)
2 Likes

I would advise against using TweenSize(), TweenPosition(), and TweenSizeAndPosition() because I have seen people, and I have experienced, having problems with these methods being extremely buggy/broken. Rather than using those methods, you can use the actual TweenService to make more advanced and reliable tweens.

1 Like

yeah i thought tween size looked easier than the actual tween service, can you give me an example of tween service?

1 Like

nevermind, i made one, it was quite simple actually:

local progress = targetToDestory.Health.Value/targetToDestory.MaxHealth.Value
			local tweenService = game:GetService("TweenService")
			local tweenInfo = TweenInfo.new(
				1, 
				Enum.EasingStyle.Linear 
			)
			local tween = tweenService:Create(
				value.TextLabel,
				tweenInfo,
				{
					Size = UDim2.new(0.9*progress, 0, 0, 30)
				}
			)
			tween:Play()

however the bar still dosn’t disappear when health’s value reaches 0

Does variable progress reach 0 when the bar is still not empty?

local progress = targetToDestory.Health.Value/targetToDestory.MaxHealth.Value
			print(progress)
			local tweenService = game:GetService("TweenService")
			local tweenInfo = TweenInfo.new(
				0.5, -- duration
				Enum.EasingStyle.Linear -- easing style
			)
			local tween = tweenService:Create(
				value.TextLabel,
				tweenInfo,
				{
					Size = UDim2.new(progress, 0, 0, 30)
				}
			)
			tween:Play()

code so far, it printed this:

it did one for 22 times before but i didn’t have enough space for the screenshot

Well, the bar won’t be empty if progress is not 0 so that’s likely the reason the bar never empties. If you want to test this you can input 0 for progress which should empty the bar. If the bar does empty, that means there is something wrong with the value of progress.

oof, it is empty. maybe something to do with this? this handles the health decreasing:

if target.Health.Value >= 0 then
			target.Health.Value = target.Health.Value - tool:GetAttribute("Damage")
			if target.Health.Value <= 0 then
				local name = target.Name
				player.Resources[name].Value = player.Resources[name].Value + 1
				target:Destroy()
			end
		end

Can you print the values of Health and MaxHealth where you previously printed progress?

the game system is a bit complicated, it might be easier if I add you in team create

You don’t need to add me to a team create session but if you want me to further inspect what’s happening you can send the place file in the form of a rbxl file.

alright, i sent you the file. let me know if theres any questions or problems

The problem appears to be that the block gets destroyed as soon as the health reaches 0 so the client never has a chance to update the bar. I put a second tween in the if-then statement for detecting mouse hovering on the block and just made the bar empty so if the block gets destroyed then bar empties and if the client doesn’t select anything the bar also remains empty. You could do other things like hiding the bar UI completely or emptying the bar then hiding the UI but this was the solution I could come up with.
Here’s what I put in the else:

		else
			previewBlock.Parent = replicatedStorage
			targetToDestory = nil
			local tweenService = game:GetService("TweenService")
			local tweenInfo = TweenInfo.new(
				0.5, -- duration
				Enum.EasingStyle.Linear -- easing style
			)
			local tween = tweenService:Create(
				value.TextLabel,
				tweenInfo,
				{
					Size = UDim2.new(0, 0, 0, 30)
				}
			)
			tween:Play()
		end

hmm intresting, i need to sleep now so i will see how to solve it tommorow. thanks for your help