Why is changing pivot in one loop not replicating

I have a loop, that’s supposed to change the position of an object, which is does and it prints 3 different pivot points correctly. However, later on in the script, it prints the 3 same pivots

for _, floor in GeneratedTower do
		floor:PivotTo(End.CFrame)
		print(floor:GetPivot())
end

for _, floor in GeneratedTower do
	print(floor:GetPivot())
end

The first there prints show that the pivots have changed, but the last print shows that all 3 are the same.
image
I do other things in the first loop that aren’t relevant to the question and the second for loop is just to show that the pivots aren’t actually changing for some reason

2 Likes

Since all three were assigned to the same pivot, I would think they should all print to be the same in the first loop. I suspect what is actually going on here, is that GetPivot is returning you a cached/out-of-date value from before the pivot was moved. You could test this theory by printing in the line before you change the pivot, and seeing if the value remains unchanged.

1 Like

Another issue is that you are using a keyword as Variable what you should never do. Try change floor to something else. Maybe Floor with a capital F

1 Like

Isn’t floor only a keyword within the math library’s namespace? The code highlighter in this forum is just making it look like a keyword erroneously.

1 Like

The first loop has more code to it, where End changes each loop, So the first loops prints are correct. It’s the second loop that’s printing incorrect values. Even though I change each floors pivot in the first loop, they just get reset back after for o apparent reason

It is still a keyword, so you shouldn’t use it. Its unlikely it does something but still.

1 Like

floor isn’t a keyword in Lua though?

Alright. Then if you want me to help debug your code, I’ll need to see all of it. I don’t think the bug is in the parts of the code you’ve shown so far.

1 Like