Frame size not changing correctly

so im trying to make an ore’s gui “health” to go down after being hit, but every time i hit the ore, the gui’s size gets set to {0, 0}, {0, 0} instead of {0.9, 0}, {1, 0}, please help

local RockFoundEvent = game.ReplicatedStorage.RockFoundEvent


RockFoundEvent.OnServerEvent:Connect(function(LocalPlayer, Ore)
	local Pickaxe = LocalPlayer.Character:FindFirstChild("Pickaxe")
	if Pickaxe == nil then return end
	
	local OreGui = Ore.HealthPart.BillboardGui
	OreGui.Enabled = true
	
	
	local PickaxePower = Pickaxe:GetAttribute("Power")
	local PickaxeDivTen = PickaxePower / 10
	
	local Damage = UDim2.new(
		PickaxeDivTen,
		0,
		1,
		0
	)
	
	print("Pickaxe Power: " .. PickaxePower)
	local OreHealth = Ore.HealthPart.BillboardGui.GreenHealth.Size
	print("Ore gui size before hit: " .. tostring(OreHealth))
	
	Ore.HealthPart.BillboardGui.GreenHealth.Size = UDim2.new(OreHealth - Damage)
	OreHealth = Ore.HealthPart.BillboardGui.GreenHealth.Size
	
	print("ore gui size after hit: " .. tostring(OreHealth))
	
end)

Try using UDim2.fromScale() instead of UDim2.new()

1 Like

i changed Local Damage from UDim2.new() to UDim2.fromScale(PickaxeDivTen) but its still the same

the problem is how you’re subtracting the health and the damage

local OreHealth = UDim2.fromScale(1, 1)
local Damage = UDim2.fromScale(0.1, 1)
print(UDim2.new(OreHealth - Damage))
--> {0, 0}, {0, 0}
	
print(OreHealth - Damage) -- You can subract the UDims without creating a new one
--> {0.899999976, 0}, {0, 0}

this still wouldn’t show the HP because you also subtracted Y size

RockFoundEvent.OnServerEvent:Connect(function(LocalPlayer, Ore)
  local Pickaxe = LocalPlayer.Character:FindFirstChild("Pickaxe")
  if not Pickaxe then return end

  local OreGui = Ore.HealthPart.BillboardGui -- You made a variable for OreGui so use it
  OreGui.Enabled = true

  local PickaxePower = Pickaxe:GetAttribute("Power")
  local PickaxeDivTen = PickaxePower / 10

  OreGui.GreenHealth.Size -= UDim2.fromScale(PickaxeDivTen, 0)
  -- Health would be {0.899999976, 0}, {1, 0} after first hit
end)
1 Like

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