AbsoluteSize returning 0 when clearly not


When I do print(ClonedUI.Health.AbsoluteSize.X) it prints 0, but I can clearly see it the Properties that it’s 757.6

1 Like

You’re printing from a local script, are you sure you’re allowing the client to properly interpret this?

I’m printing from the server…

o.O, I thought the green tag was client, and blue meant server.
Can I see the active code around the printing of absoluteSize?

It’s in the SS in the main post

This is a theory, don’t flame me if I’m wrong

Methinks this is because ClonedUI starts off parented to nil, so auto-updating properties don’t update when not a part of DataModel.

Does parenting sooner do anything?

Oh yeah, that is true. The clonedUi isn’t parented. But that shouldn’t deprecate its properties?

I tried this

ClonedUI.Parent = enemy.Head
ClonedUI.Health.Bar.BarHealth.Size = UDim2.new(0, ClonedUI.Health.AbsoluteSize.X, 0.6, 0)

Didn’t change anything, still was set to 0 :confused:

If I remember correctly there’s a process step that happens after the GUI is parented and scripts start for determining the AbsoluteSize. If you add a wait before the AbsoluteSize check does that help?

You should really be handling anything related to UI on the client, not the server, passing information using RemoteEvents or just object value instances. If you handle UI on the server, you are likely to encounter problems such as this where replication is funky.

1 Like

Still didn’t work ://////////////////

Oh whoops, yeah, I don’t think AbsoluteSize is replicated to the server. I just realized you were doing this from the server.

3 Likes

Okay, I finally ‘solved’ this.
If you try setting the size to offset from the beginning, it will print normally.
@CompilerError AbsoluteSize does replicate but not the scale, instead it returns 0

Btw to convert your size to scale do this:

local viewSize = EnemyUI.AbsoluteSize

ClonedUI.Health = UDim2.new(0,viewSize.X/ClonedUI.Health.AbsoluteSize.X,0,viewSize.Y/ClonedUI.Health.AbsoluteSize.Y)

Note that printing AbsoluteSize may return when the size is scale but coding wise, you can keep using the constructors’ values.

2 Likes

This isn’t really solving anything. UI should always be created or handled on the client, never on the server. BillboardGuis work best when located in PlayerGui and making use of the adornee property. This is really just the tip of the iceberg, don’t expect anything to work reliably with server sided UI

What you’re suggesting is improvement upon his coding. I am appealing to the answer he was looking for.

The bug arised from that absoluteSize because the inputted value was a scale. I am not in the interest of improving his code, I am just giving him the solution he required.

The reason AbsoluteSize returns 0 in your code is most likely due to you only using the scale arguments of its size. They can’t and won’t be calculated on gui objects that are parented to nil (Clone() parents to nil).

Either temporarily parent the cloned object to the same frame as the original object, or base your size calculations on the original object’s AbsoluteSize.

1 Like

I was already doing that

ClonedUI.Parent = enemy.Head
	
	wait()
	
	ClonedUI.Health.Bar.BarHealth.Size = UDim2.new(0, ClonedUI.Health.AbsoluteSize.X, 0.6, 0)

Have you at least tried it on the client? What you’re doing is fundamentally wrong

I’ve tried, I get constant errors. For one, the event fires well before the player has joined, thus causing the client side to never pick up on it

CreateEnemyUI:FireClient(player, TrollClone)

Then on the client

local function AddTag(enemy)
	local EnemyUI = script:WaitForChild('EnemyUI')
	local ClonedUI = EnemyUI:Clone()
	
	local EnemyStats = require(enemy.Stats)
	
	local Level = math.random(EnemyStats.MinLevel, EnemyStats.MaxLevel)
	ClonedUI.Label.Text = enemy.Name .. ' [Lvl. ' .. Level .. ']'
	
	local Humanoid = enemy.Humanoid
	Humanoid.MaxHealth = EnemyStats.Health
	Humanoid.Health = Humanoid.MaxHealth
	Humanoid.WalkSpeed = EnemyStats.WalkSpeed
	
	ClonedUI.Health.HealthLabel.Text = Humanoid.Health .. '/' .. Humanoid.MaxHealth
	ClonedUI.Health.Bar.BarHealth.Text = ClonedUI.Health.HealthLabel.Text
	
	ClonedUI.Health.Bar.Size = UDim2.new(1, 0, 1, 0)
	
	ClonedUI.Parent = enemy.Head
	
	wait()
	
	ClonedUI.Health.Bar.BarHealth.Size = UDim2.new(0, ClonedUI.Health.AbsoluteSize.X, 0.6, 0)
	
	local function HealthChanged(newHealth)
		local RoundedNumber = math.floor(newHealth + 0.5)
	
		ClonedUI.HealthLabel.Text = RoundedNumber .. '/' .. Humanoid.MaxHealth
		ClonedUI.Health.Bar.BarHealth.Text = ClonedUI.Health.HealthLabel.Text
	
		ClonedUI.Health.Bar:TweenSize(UDim2.new(RoundedNumber / Humanoid.MaxHealth, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
	end
end

CreateEnemyUI.OnClientEvent:Connect(AddTag)

I can’t get EnemyStats, as I can’t pass an object through remote events. Another problem I’m gonna face with this is other players wont see the UI, as they havent spawned it. Or would FireAllClients be better?

Making it client did absolutely nothing

ClonedUI.Parent = enemy.Head
	
	wait()
	print(ClonedUI.Health.AbsoluteSize.X) -- prints 0
	ClonedUI.Health.Bar.BarHealth.Size = UDim2.new(0, ClonedUI.Health.AbsoluteSize.X, 0.6, 0)