UDim2.new works badly

				hit:FindFirstChild("SurfaceGui").GreenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value), 1)

So I have a line in which I change the size of the line, so that the player can see the changes. But for some reason the following happens:

why is this line flying up?

hit:FindFirstChild("SurfaceGui").GreenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 0, 0), 1)

In this updated code, the UDim2.new() function call now includes the necessary scale and offset values for the UDim2 object. The scale is set to hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, and the offsets are set to 0.

Make sure to replace the line in your script with this updated version.

OK I replaced the line with your version, but nothing changes

Check that the Current and Max values are accessible as child objects of the hit object. Use print(hit:FindFirstChild("Current")) and print(hit:FindFirstChild("Max")) to check if these values are correctly found.

or try this ive set the anchor point

hit:FindFirstChild("SurfaceGui").GreenGround:TweenSizeAndPosition(
    UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 0, 0),
    UDim2.new(0.5, 0, 0.5, 0),
    Enum.EasingDirection.InOut,
    Enum.EasingStyle.Quad,
    1
)

Снимок экрана 2023-06-30 в 12.56.15
Снимок экрана 2023-06-30 в 12.56.34
Снимок экрана 2023-06-30 в 12.56.40

print(hit:FindFirstChild("Current").Value, hit:FindFirstChild("Max").Value)

yes the values are found correctly

Did the new code work with the anchor?

What do you mean? I have this script by the tool. There I get another object (wall) and change this strip. That is, my hit is the part that I get

local surfaceGui = hit:FindFirstChild("SurfaceGui")
local greenGround = surfaceGui.GreenGround

-- Set the anchor and position properties
greenGround.AnchorPoint = Vector2.new(0.5, 0.5)
greenGround.Position = UDim2.new(0.5, 0, 0.5, 0)

-- Tween the size
greenGround:TweenSizeAndPosition(
    UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 0, 0),
    UDim2.new(0.5, 0, 0.5, 0),
    Enum.EasingDirection.InOut,
    Enum.EasingStyle.Quad,
    1
)

the AnchorPoint property of GreenGround is set to (0.5, 0.5) , which means it will be centered within its parent. The Position property is set to UDim2.new(0.5, 0, 0.5, 0) , which also centers the object.

as you can see now he is flying, upwards. I don’t think you should touch the position. I kind of just need to resize the x-size, that’s all. Isn’t it?

Oh okay try this then this should finnaly work

local surfaceGui = hit:FindFirstChild("SurfaceGui")
local greenGround = surfaceGui.GreenGround

greenGround:TweenSize(
    UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0),
    Enum.EasingDirection.InOut,
    Enum.EasingStyle.Quad,
    1
)

Do I have to remove the anchorpoint?

greenGround.AnchorPoint = Vector2.new(0.5, 0.5)
greenGround.Position = UDim2.new(0.5, 0, 0.5, 0)

you want it to slide to the left right?

Yes. That’s how you know there’s health in different games. I want the green bar to move to the left when I do damage. Like if the wall has 5 health, the green bar is on the left. Something like this

maybe this im really trying to do this its hard when you cant play test and try it

local surfaceGui = hit:FindFirstChild("SurfaceGui")
local greenGround = surfaceGui.GreenGround

local targetSize = UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0)
local targetPosition = UDim2.new(targetSize.X.Scale * -0.5, 0, 0, 0)

greenGround:TweenSizeAndPosition(
    targetSize,
    targetPosition,
    Enum.EasingDirection.InOut,
    Enum.EasingStyle.Quad,
    1
)

hmm… I tried changing the X coordinate manually. And it went like this? That’s very strange.

try this

greenGround:TweenSize(UDim2.new(current / max, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1)

greenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1)

im sorry but im not really too sure what to do else