Y cannot be assigned too

I’m basically making a script that lays out the ui that is supposed to look like this in the end:

endresult

But when I make this script I get an error “Y cannot be assigned too” and this probably happens with the x axis as well but I havent seen an error like that yet.

Script: (if the index is an even number, it will go on the left side, if the index is an odd number, it will go below)

local blocks = game.ReplicatedStorage:WaitForChild("Blocks")
local test = script.Parent:WaitForChild("Frame"):WaitForChild("Test")

for i, v in pairs(blocks:GetChildren()) do
	if i % 2 == 0 then -- index is an even number
		local button = test:Clone()
		button.Name = v.Name
		button.Text = v.Name
		button.Visible = true
		button.Position.X = button.Position.X + UDim2.new(0.534, button.Position.Y)
	else -- index is an odd number
		local button = test:Clone()
		button.Name = v.Name
		button.Text = v.Name
		button.Visible = true
		button.Position.Y = button.Position + UDim2.new(button.Position.X, 0.065)
	end
end

Basically, this script goes through everything in the blocks folder and adds a button for everything inside it

1 Like
local blocks = game.ReplicatedStorage:WaitForChild("Blocks")
local test = script.Parent:WaitForChild("Frame"):WaitForChild("Test")

for i, v in pairs(blocks:GetChildren()) do
	if i % 2 == 0 then -- index is an even number
		local button = test:Clone()
		button.Name = v.Name
		button.Text = v.Name
		button.Visible = true
		button.Position = button.Position + UDim2.fromScale(0.534, button.Position.Y.Scale)
	else -- index is an odd number
		local button = test:Clone()
		button.Name = v.Name
		button.Text = v.Name
		button.Visible = true
		button.Position = button.Position + UDim2.fromScale(button.Position.X.Scale, 0.065)
	end
end

.Position = UDim2.new(0,0,0,0) <the only correct way to type it

You need to build a new UDim2. You can’t set properties of an existing UDim2.

UDim2.new(button.Position.X.Scale, button.Position.X.Offset, 0.534, button.Position.Y.Offset)

By the way – avoid using precise scales like 0.534. Use Offset when you need to!

2 Likes

Scale and offset cant be compared they simply do different things…

Btw You might be practicing coding but Roblox has a set of helpful objects you can use, that does what your trying to automatically. Look up these:

1 Like