Scaling down a GUI when an object is clicked

Hi again everyone

I want to create a “health” bar for an object, and when you click the object, the health bar will go down 1/4 of 200, which will result is 1/4 being remove from the health bar. And then, when the bar is on zero, the object gets destroyed.

I have an idea of how to destroy the object, create the GUI, add one the values, etc, etc but I just cant figure out how to change the size of the GUI by -50 each time.

Thanks everyone.

Why not just do script.Parent.Size = Vector3.new(script.Parent.Size/2,script.Parent.Size, script.Parent.Size) ?

UDim2.fromScale* .

I thought he wanted to size the part.

I get the error

Players.pevdn.PlayerScripts.showGui:11: attempt to perform arithmetic (div) on UDim2 and number

when implementing this

(and adding msix’s changes)

Are you trying to size the part or UI? In the title it says scaling GUI, yet in the text it says scaling Object.

Do this:

script.Parent.Size = UDim2.fromScale(script.Parent.Size.X.Scale / 2, script.Parent.Size.Y.Scale / / 2)

Oop- mean the GUI, i’ll edit it now.

Oh okay yeah for Ui you use Udim2 for Parts you use Vector3

All you have to do which Msix is just divide the size by 2 using Udim2

by the way- does this work with a localscript?

You have to set the bar to this size everytime

Horizontal bar:

Udim2.new(health/maxHealth, 0, 1, 0)

Vertical bar:

Udim2.new(1, 0, health/maxHealth, 0)

Put the bar inside another frame for background.
What this calculation basicly does is dividing the current value by max.
This provides you with a value between 0 and 100% of the max value.

10 / 100 = .1
50 / 100 = .5

it also works when the max value is higher than 100

75 / 500 = .15
100 / 450 = .22222222

because you put it in the scale 1 = 100% of its parent size.
.5 will fill the bar 50%

Yes

A
A

A
A

A
A
A

Aajwhhwhehhxbxbbdhdhhdhhshsbs 30 is such a bad limit

Yes, this should be inside a local script.

I was just double checking incase it would work in a server script, but now the GUI will not appear:

Here is my format:

Don’t do it in a server script, that will overload the server and cause tons of lag. Interacting with UI should be handled on the client and in some cases completely handled by the client.

Its not in a serverscript, its in a local script.

Can you send your full code then?

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(gui)
	local frame = workspace.Folder.kabob.BillboardGui.Frame
	frame.Size = UDim2.fromScale(frame.Size.X.Scale / 2, frame.Size.Y.Scale)
end)

I guess the size of the frame isn’t scaled so try this:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(gui)
	local frame = workspace.Folder.kabob.BillboardGui.Frame
	frame.Size = UDim2.fromOffset(frame.AbsoluteSize.X / 2, frame.AbsoluteSize.Y)
end)