Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Changing a UDim2 Value?

I'm trying to change the size of a Frame using a UDim2 value, and the problem is I want some values to remain constant. I'm also trying to use scale instead of offset, so the GUI fits universally.

Here's the script:

coroutine.resume(coroutine.create(function()
	time = fuel/10
	while not trigger and fuel < 100 do
		time = tick() - time
		fuel = time*10
		if fuel > 100 then fuel = 100 end
		fuelbar.Size = UDim2.new(fuel*2,0,Y,0) --I need a way to substitute the y-scale size value in for Y
		game:GetService("RunService").RenderStepped:wait()
	end
end))

2 answers

If I understand the question correctly, you want the Y scale size to be a constant. In that case, you literally substitute the Y with a constant, like so:

coroutine.resume(coroutine.create(function()
    time = fuel/10
    while not trigger and fuel < 100 do
        time = tick() - time
        fuel = time*10
        if fuel > 100 then fuel = 100 end
        fuelbar.Size = UDim2.new(fuel*2,0,0.2,0) -- Here, I replaced the Y with a constant,  in this case 0.2
        game:GetService("RunService").RenderStepped:wait()
    end
end))

1 comment

0

I do want the y to be constant, but I want it to be the previous size of the UDim2 value. I figured it out myself though, thanks

I was able to answer my own question by digging a little deeper into the roblox wiki. The scale of a UDim2 value can be specified like so:

local v = UDim2.new(0,0,v.Size.Y.Scale,0)

This discussion is preserved as it was. New answers, comments, and votes are closed.