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.
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.
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.
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