Mk, so here's what I think, I think it's not a problem in the script, it's a problem in the GUI. Assuming the health bar displays your health properly and updates itself, I think you didn't put the health bar frame inside another frame. When you say
1 | script.Parent.Parent.Size = UDim 2. new(health/maxHealh, 0 , 0 , 24 ) |
then it does a health bar across the whole screen because it's scaling the frame across it's parent. To sum it up, to fix it, you need to make another frame in the same screen GUI and put the frame you want to scale inside of it. This new frame needs to be about the size you want the health bar to be and move the scaling frame onto it. If it still scales off a little bit then just do something like
1 | script.Parent.Parent.Size = UDim 2. new((health/maxHealth)* 0.95 , 0 , 0 , 24 ) |
to make it a little bit shorter. Change 0.95 and test it over and over again until it's the right size.