How to use 'int value' in a frame X size (equal int value to frame size)

Does anyone know how I could get the size of a frame (from the x axis) and change its value with the ‘int value’?

I need to use the ‘int value’ to change its value to my liking and make this value show in the frame when I change this int value… how could i do that?

What do you mean? Like if you change the intvalue then the frame’s x size gets smaller?

1 Like

Yes! that’s what i want to do

Using scale or pixels?________

The same as when you change the frame size in a gui, i think it’s scale, right? :open_mouth:

Scale is the value that takes uses a percentage of the screen size. You could do something like this, changing the intvalue’s value to anything between 0-100 will change the frames size.


local intvalue = --define
local frame = -- define
local ydefault = --number 0 - 1, how big it should be on the y axis.

intvalue.Changed:Connect(function()
     if intvalue.Value <= 100 and intvalue.Value >= 0 then
     frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)
     end
end)

while wait(1) do --just to test if it changes
     intvalue.Value = math.random(1,100)
end
1 Like

Great! so if i change the intvalue.Value = 30 ingame will the frame size change?

Yes it should change to be 1/3 of the screen size. If you want to use pixels instead tell me.

How could I apply it with pixels? :open_mouth:

local intvalue = --define
local frame = -- define
local ydefault = --define default y pixels

intvalue.Changed:Connect(function()
     frame.Size = UDim2.new(0,intvalue.Value,0, ydefault)
end)

while wait(1) do --just to test if it changes delete this if you want
     intvalue.Value = math.random(1,500)
end
1 Like

Thanks you a lot! I’m going to apply this to my project to see how it works :open_mouth: :innocent: :innocent: :innocent:

1 Like

I gotta go, but if you need anymore help I’ll be free in like 30 minutes. You can ask any more questions and I’ll get back to you as soon as I can. :slight_smile: .

1 Like

Great! :smiley: thanks you a lot bro, take care!

1 Like

Hello, it’s me, again
I’m having some problems with the ‘ingame’ code, how could I adjust it to fit the same size?

I would like this bar to fit the same size. :frowning:

y1

y3

y4

THE BAR FULL SIZE


local intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"

local frame = script.Parent
local ydefault = 1

intvalue.Changed:Connect(function()
     frame.Size = UDim2.new(0,intvalue.Value,ydefault, 0)
end)

while wait(1) do --just to test if it changes delete this if you want
     intvalue.Value = math.random(1,500)
end
1 Like

I just did it and it shows me that 100 is half the bar

local intvalue = Instance.new("IntValue")

intvalue.Name = "Stamina"

local frame = script.Parent

local ydefault = 1

intvalue.Changed:Connect(function()

frame.Size = UDim2.new(0,intvalue.Value,ydefault, 0)

end)

intvalue.Value = 100

--while wait(1) do --just to test if it changes delete this if you want

--intvalue.Value = math.random(1,100)

--end

daas

Instead of using pixels I would use scale. 100 is full bar 0 is empty. Later today after school I’m going to make a Community Tutorial on a sprint bar gui, maybe that could help too.

local intvalue = Instance.new("IntValue")

intvalue.Name = "Stamina"

local frame = script.Parent

local ydefault = 1

intvalue.Changed:Connect(function()

frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)

end)

intvalue.Value = 100

--while wait(1) do --just to test if it changes delete this if you want

--intvalue.Value = math.random(1,100)

--end
1 Like

Great! This works! Thank you very much for your time, I appreciate it :smiley:

1 Like

Glad I could help :slight_smile: ! _______

1 Like

Can I ask you one last question? I would like to know that my code is wrong, if you could help me with this it would really be the last thing for today I am ready

local intvalue = Instance.new("IntValue")

intvalue.Name = "Stamina"

local frame = script.Parent

local ydefault = 1

intvalue.Changed:Connect(function()

	frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)

end)

intvalue.Value = 1

local stamina = intvalue.Value

if stamina >= 0 then
	for i = 0, 50, 5 do
		stamina = i
		print("Part 1. stam is: " .. stamina)
		wait(2)
		if stamina >= 50 then
			print("end of part 1.")
			wait(2)
			for i2 = 50, 100, 5 do
				stamina = i2
				print("Part 2. stam is: " .. stamina)
			end
		end
	end
end
1 Like