Imagelabel won't scale based of intvalue value

  1. What do you want to achieve? I’m trying to make a script to scale an ImageLabel based off of an intvalue

  2. What is the issue? It just won’t scale here is a video

  3. What solutions have you tried so far? I looked on the dev forum and couldn’t find anything that helps.

My script is a normal script and is located in StarterPlayer.StarterCharacterScripts
Here is my script

while true do
	if script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 91 or 92 or 93 or 94 or 95 or 96 or 97 or 98 or 99 or 100 then
		script.Parent.Frame.IFHB.Size = UDim2.new(1,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 81 or 82 or 83 or 84 or 85 or 86 or 87 or 88 or 89 or 90 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.9,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 71 or 72 or 73 or 74 or 75 or 76 or 77 or 78 or 79 or 80 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.8,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 61 or 62 or 63 or 64 or 65 or 66 or 67 or 68 or 69 or 70 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.7,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 51 or 52 or 53 or 54 or 55 or 56 or 57 or 58 or 59 or 60 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.6,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 41 or 42 or 43 or 44 or 45 or 46 or 47 or 48 or 49 or 50 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.5,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 31 or 32 or 33 or 34 or 35 or 36 or 37 or 38 or 39 or 40 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.4,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 or 29 or 30 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.3,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 or 20 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.2,0,.9,0)
	elseif script.Parent.Parent.Parent.InfectionStuff.InfectedHealth.Value == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 then
		script.Parent.Frame.IFHB.Size = UDim2.new(.1,0,.9,0)
	end
	wait()
end

I would prefer if you would tell me the part that is wrong with my script.
Also I’m sorry if this is the wrong place for this

1 Like

If you are ganna do something like

if value == 1 or 2 or 3

-- you need to do

if value == 1 or value == 2 or value == 3

Btw this is a very unefficient way to tween UI

if value == 1 or 2 or 3

is basicly what I’m doing but give me a sec to change it

Same issue as before. If you have a better way for me to scale it you can tell me if you wish

If you’re trying to scale a bar the formula would be something like.

UDim2.new(min/max, 0,0,0)
while wait() do
local LABEL = script.Parent.Frame.IFHB
local INFECTED_HEALTH = script.Parent.Parent.Parent.InfectionStuff.InfectedHealth
LABEL.Size = UDim2.new(INFECTED_HEALTH.Value / 100, 0, .9, 0)
end

Or you can do :TweenSize()

Well the InfectedHealth can range from 100 to 0 give me a sec to test it

I edited the code it will divide the value by 100

wouldn’t it be better to do

local InfectionHealth = script.Parent.Parent.Parent.InfectionStuff.InfectedHealth
local Gui = script.Parent.Frame.IFHB

local function onInfectionHealthChanged()
   Gui:TweenSize(Udim2.new(InfectionHealth.Value/100 0, 0.9,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.4, false)
end

InfectionHealth:GetPropertyChangedSignal("Value"):Connect(onInfectionHealthChanged)

onInfectionHealthChanged()
1 Like

Nither of them work. The output still says nothing sorry it took me a bit to respond i was doing something

Did you change the value on the server or on the client?

I have a brick setup to change the InfectedHealth value of the player that touched it

what does the script look like

local InfectionHealth = script.Parent.Parent.Parent.InfectionStuff.InfectedHealth
local Gui = script.Parent.Frame.IFHB

local function onInfectionHealthChanged()
	Gui:TweenSize(UDim2.new(InfectionHealth.Value/100 ,0, 0.9,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.4, false)
end

InfectionHealth:GetPropertyChangedSignal("Value"):Connect(onInfectionHealthChanged)

onInfectionHealthChanged()

I mean the script for the brick

oh

local debounce = false
script.Parent.Touched:Connect(function(obj)
	if debounce == false then
		debounce = true
		local h = obj.Parent:FindFirstChild("Humanoid")
		if h then
			h.Parent.InfectionStuff.InfectedHealth.Value -= 38
		end
		wait(5)
		debounce = false
	end
end)

it works as it is meant to

Not sure, but this might just be very simple. You would decrease the 2nd number of the X axis of the Size of the ImageLabel (It will depend, assuming it is decreasing it to the left, then this is correct.)

Im going off of scale so the GUI doesnt expand when you get farther away

I’m puzzled, but try this

local InfectionHealth = script.Parent.Parent.Parent.InfectionStuff.InfectedHealth
local Gui = script.Parent.Frame.IFHB

local function onInfectionHealthChanged()
   Gui.Size = Udim2.new(InfectionHealth.Value/100, 0, 0.9,0)
end

onInfectionHealthChanged()
InfectionHealth:GetPropertyChangedSignal("Value"):Connect(onInfectionHealthChanged)

I don’t under stand why this isn’t working :confused: