Misconfigured UDim2.new()

				greenGround:TweenSize(UDim2.new(0, 0, hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5)

So here I have a script that looks at the current health of the wall and the maximum and looking at it adjusts the health bar, but for some reason instead of was like this (this is just an example of what I want to achieve if for example the wall was half of the maximum health):

But instead it works like this:

why does it work like that? As I understand it, I set up the TweenSize wrong, but how, I don’t know?

1 Like

Since you didn’t provide the full code, I tried to fix the error in the script you sent me.

greenGround:TweenSize(UDim2.new(0, 0, hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5)

If that doesn’t work, send the full script and I will try to analyze the error better.

no it did not help, well as you asked a full script:(but only the part that relates to the wall)

local player = game:GetService("Players").LocalPlayer
local tween = game:GetService("TweenService")
local debounce1 = true
local debounce2 = true
local function dynamiteTouched()
	if script.Parent:WaitForChild("DynamiteValue").Value ~= nil then
		script.Parent:WaitForChild("DynamiteValue").Value.Touched:Connect(function(hit)
			if hit.Name == "Sand_1" and debounce2 == true then
				debounce2 = false
				hit:FindFirstChild("Current").Value -= player.leaderstats.Damage.Value
				
				hit:FindFirstChild("SurfaceGui").HpCount.Text = hit:FindFirstChild("Current").Value.. " / ".. hit:FindFirstChild("Max").Value
				
				local surfaceGui = hit:FindFirstChild("SurfaceGui")
				local greenGround = hit:FindFirstChild("SurfaceGui"):FindFirstChild("BackGround").GreenGround
				
				greenGround:TweenSize(UDim2.new(0, 0, hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5)		
				
				if hit:FindFirstChild("Current").Value <= 0 then
					wait(0.1)
					hit.Parent = game:GetService("ReplicatedStorage").RPWalls
					
					local vfx = workspace.Smoke_1:Clone()
					vfx.Parent = workspace.vfx
					vfx.Position = hit.Position
					vfx.Anchored = true
					vfx.ParticleEmitter:Emit()
					
					wait(0.4)
					
					vfx:Destroy()
					
				end
				wait(1)
				debounce2 = true
			end
		end)
	end
end
script.Parent:WaitForChild("DynamiteValue"):GetPropertyChangedSignal("Value"):Connect(dynamiteTouched)

Looking at the provided script, it seems like the issue lies in the line where you are using greenGround:TweenSize(). The code snippet you shared is attempting to adjust the size of greenGround based on the current and maximum values of the wall’s health.

To fix the issue, you need to update the greenGround:TweenSize() function to use the correct parameters. Here’s the corrected line of code:

greenGround:TweenSize(UDim2.new(0, greenGround.Size.X.Offset, hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5)

In this corrected version, we maintain the original width of greenGround by using greenGround.Size.X.Offset as the width component in the UDim2 size. This ensures that the width remains the same while only adjusting the height based on the health values.

No, nothing has changed. If anything I need to change by Y, here:

So I’m sorry. I will not be able to resolve your error. Forgiveness.

it should be

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

the first parameter is X Scale, then X Offset, then Y Scale, then Y Offset

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.