Part's position not updating even though printed position is different

I am making a system where when the player destroys all the walls and makes it to the end, it resets the walls back to their original position. However, I am getting an issue which occasionally happens where the last wall’s position doesn’t update back to its original space however the code prints its position differently.
The code:

--the function I use to remove the wall
local function removeWall(wall)
	playSound:Fire("glassDestroy")
	local newPosition = Vector3.new(wall.Position.X,wallYFallen,wall.Position.Z)
	local tween = tweenService:Create(wall,tweenInfo,{Position=newPosition}):Play()
	
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")
	camShake:Shake(cameraShaker.Presets.Bump)
end


local function replenishWalls(world,walls)
	for i, wall in pairs(walls:GetChildren()) do
		print(wall)
		print(wall.Position)
		wall.Position = Vector3.new(wall.Position.X,wallYNormal,wall.Position.Z)
		print(wall.Position)
		local maxHealth = windowHealth[tonumber(world.Name)][tonumber(wall.Name)]
		local health = wall:WaitForChild("Health")
		local healthBar = wall:WaitForChild("SurfaceGui"):WaitForChild("Frame"):WaitForChild("healthBar")
		health.Value = maxHealth
		updateHealthBar(wall,maxHealth,health,healthBar)
	end
	alreadyTouched = false
end

for i, world in pairs(worlds:GetChildren()) do
	local walls = world:WaitForChild("walls")
	for i, wall in pairs(walls:GetChildren()) do
		updateWallInfo(wall,world)
	end
	walls.ChildAdded:Connect(function(wall)
		updateWallInfo(wall,world)
	end)
	local spawnLocation = world:WaitForChild("spawn")
	local winArea = world:WaitForChild("winZone")
	local winZone = zone.new(winArea)
	winZone.localPlayerEntered:Connect(function()
		if alreadyTouched == false then
			local canAward = checkCompleted(walls)
			if canAward == true then
				reachedEnd:FireServer()
				alreadyTouched = true
				local character  = player.Character or player.CharacterAdded:Wait()
				character:MoveTo(spawnLocation.Position) 
				replenishWalls(world,walls)
				fireConfetti:Fire("blast")
				playSound:Fire("reachedEnd")
			end
		end
	end)
end

When i test the game,its always the 8th and final wall that doesn’t move back to its original position as you can see below where my mouse is:

however according to the print statements, it should have:

but that 2nd position print hasnt updated onto the instances positon as it still displays the origonal one.
image

Also, when I click on the wall instance printed out, it directs me to the workspace where that part is so I dont think the issue is to do with the code updating the position of a different part:


Anyone know why this may be happening?

3 Likes