Moving GUIObjects using a loop

I’m using a rudimentary script to make a heart shape via coordinates in a table. The heart shape forms using a repeat until loop. The problem is that 6 of the ‘parts’ of the heart stop at the 6th coordinate instead of travelling to the 7th and final coordinate.

for i, v in pairs(postab) do
	if not debounce then
		debounce = true
		table.insert(tabtab, 7, v)
		local newHP = HeartPart:Clone()
		newHP.Parent = Frame.newHP
		newHP.Position = UDim2.new(tabtab[1][1][1], tabtab[1][1][2], tabtab[1][2][1], tabtab[1][2][2])
		newHP.Visible = true
		for _, pos in pairs(tabtab) do
					print("Postab".." "..i, "and tabtab".." ".._)
					if pos == "Finished" then
						table.remove(tabtab, 7)
						Next = 0
						debounce = false
					else
						local tabpos = UDim2.new(pos[1][1], pos[1][2], pos[2][1], pos[2][2])
						local xdiff = tabpos.X.Scale - newHP.Position.X.Scale
						local ydiff = tabpos.Y.Scale - newHP.Position.Y.Scale
						local xchange = xdiff/5
						local ychange = ydiff/5
						if newHP.Position ~= tabpos then
							repeat
								wait(.01)
								--print(newHP.Position, "This has been made via number".._)
								newHP.Position = UDim2.new(newHP.Position.X.Scale + xchange, newHP.Position.X.Offset, newHP.Position.Y.Scale + ychange, newHP.Position.Y.Offset )
								local xdiffnew = tabpos.X.Scale - newHP.Position.X.Scale
								local ydiffnew = tabpos.Y.Scale - newHP.Position.Y.Scale
							until xdiffnew <= 0.0001 and ydiffnew <= 0.0001
						end
					end
				end
			end
end

This is just a bad way to draw a heart.
I recommend instead, if you’re looking to generate pieces, use a math equation.

For example, x^2+y^2+|x|y=1 on a graph makes a heart. Results on desmos:
image

Hopefully you can instead use math, rather than an array!

2 Likes

Yeah, I thought about doing that. I only made the code in the first place to try UDim2 values since I’m not really familiar with them. I’m just wondering what’s the issue with the code I made. I just find it strange that it’s the same 6 points that glitch.

I’m not sure. It is either with the way it progresses the index through the array, or how the data is read/stored. The code is a bit too messy for me to read, unfortunately.