Changing the size of a GUI with a Variable

Hi, i have A Script that while true loops to change the size of an image in a GUI based on an IntValue object. This is the script:

while true do
  wait()
  local Image = script.Parent.Aim1
  local player = game.Players.LocalPlayer
  local Val3 = game.Workspace[player.Name.."F"][player.Name.."F"]:WaitForChild("CrossairSize")
  Image.Size = UDim2.new(0 ..Val3.Value.. 0 ..Val3.Value)
end

The size of the object ended like this:

Size: 080080,0,0,0

I want the script to execute this:

Size 0,80,0,80

(80 is the value in the Int)

Thanks

What you are doing right now is putting all the values together, that’s why you get such output. What you need to do is add comas.

while true do
  wait()
  local Image = script.Parent.Aim1
  local player = game.Players.LocalPlayer
  local Val3 = game.Workspace[player.Name.."F"][player.Name.."F"]:WaitForChild("CrossairSize")
  Image.Size = UDim2.new(0, Val3.Value, 0, Val3.Value)
end

I also suggest using UDim2.fromScale() because you will be setting the scale size value of the GUI which means that the GUI will be scaled properly for devices.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.